该视图未返回 HttpResponse 对象.它返回 None 代替 [英] The view didn't return an HttpResponse object. It returned None instead
本文介绍了该视图未返回 HttpResponse 对象.它返回 None 代替的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下简单的看法.为什么会导致这个错误?
I have the following simple view. Why is it resulting in this error?
视图 auth_lifecycle.views.user_profile 未返回 HttpResponse 对象.它返回 None .
"""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))
推荐答案
因为视图必须返回 render
,而不仅仅是调用它.最后一行改为
Because the view must return render
, not just call it. Change the last line to
return render(request, 'auth_lifecycle/user_profile.html',
context_instance=RequestContext(request))
这篇关于该视图未返回 HttpResponse 对象.它返回 None 代替的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文