The view didn't return an HttpResponse object. It returned None instead
The view didn't return an HttpResponse object. It returned None instead
I have the following simple view. Why is it resulting in this error?
The view auth_lifecycle.views.user_profile didn't return an HttpResponse object. It returned None instead.
The view auth_lifecycle.views.user_profile didn't return an HttpResponse object. It returned None instead.
"""Renders web pages for the user-authentication-lifecycle project."""
from django.shortcuts import render
from django.template import RequestContext
from django.contrib.auth import authenticate, login
def user_profile(request):
"""Displays information unique to the logged-in user."""
user = authenticate(username='superuserusername', password='sueruserpassword')
login(request, user)
render(request, 'auth_lifecycle/user_profile.html',
context_instance=RequestContext(request))
3 Answers
3
Because the view must return render
, not just call it. Change the last line to
render
return render(request, 'auth_lifecycle/user_profile.html',
context_instance=RequestContext(request))
I had the same error using an UpdateView
I had this:
if form.is_valid() and form2.is_valid():
form.save()
form2.save()
return HttpResponseRedirect(self.get_success_url())
and I solved just doing:
if form.is_valid() and form2.is_valid():
form.save()
form2.save()
return HttpResponseRedirect(reverse_lazy('adopcion:solicitud_listar'))
if qs.count()==1:
print('cart id exists')
if ....
else:
return render(request,"carts/home.html",{})
Such type of code will also return you the same error this is because
of the intents as the return statement should be for else not for if statement.
above code can be changed to
if qs.count()==1:
print('cart id exists')
if ....
else:
return render(request,"carts/home.html",{})
This may solve such issues
i have faced the same error that is mentioned in the question but i got due to the intents as in the first code the return statement is for the second if statement but not for the first thats the reason i got "that view didn't return an HttpResponse object. It returned None instead." when i set it to first if statement then it worked
– Ravi Teja Mureboina
Jul 1 at 6:00
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
what are you sugesting the 2 code snippets are just the same
– Muhammad Omer Aslam
Jul 1 at 2:36