Django 告诉我我的登录视图没有返回 HttpResponse 对象:
The view accounts.views.login didn't return an HttpResponse object.
但是,我在render_to_response()
任何地方都在使用,并且视图无法在没有得到响应的情况下完成解析。这是代码:
def login(request):
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
auth_login(request, user)
render_to_response('list.html')
else:
error = "It seems your account has been disabled."
render_to_response('list.html', {'error': error})
else:
error = "Bad login information. Give it another go."
render_to_response('list.html', {'error': error})
else:
error = "Bad login information. Give it another go."
render_to_response('list.html', {'error': error})
else:
error = "Whoa, something weird happened. You sure you're using the form on our site?"
render_to_response('list.html', {'error': error})
我确信代码可以更高效(更少的渲染),但这应该有效,对吗?