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.
"""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))
This question is related to
python
django
django-views
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'))
Python is very sensitive to indentation, with the code below I got the same error:
except IntegrityError as e:
if 'unique constraint' in e.args:
return render(request, "calender.html")
The correct indentation is:
except IntegrityError as e:
if 'unique constraint' in e.args:
return render(request, "calender.html")
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
Source: Stackoverflow.com