该视图未返回HttpResponse对象。它返回None

浏览:43日期:2024-03-06
如何解决该视图未返回HttpResponse对象。它返回None?

因为视图必须 返回 render,而不仅仅是调用它。将最后一行更改为

return render(request, ’auth_lifecycle/user_profile.html’, context_instance=RequestContext(request))解决方法

我有以下简单的看法。为什么会导致此错误?

The view auth_lifecycle.views.user_profile didn’t return an HttpResponseobject. It returned None instead.

'''Renders web pages for the user-authentication-lifecycle project.'''from django.shortcuts import renderfrom django.templateimport RequestContextfrom django.contrib.auth import authenticate,logindef 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))

相关文章: