n0p*_*0pe 0 python authentication django http
Django告诉我,我的登录视图没有返回一个HttpResponse对象:
The view accounts.views.login didn't return an HttpResponse object.
Run Code Online (Sandbox Code Playgroud)
但是,我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})
Run Code Online (Sandbox Code Playgroud)
我确信代码可以更高效(渲染更少),但这应该有效,对吗?
你错过了回报
return render_to_response('list.html', {'error': error})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
118 次 |
| 最近记录: |