我正在 Django 中制作登录表单。当我点击登录提交按钮时,它给出了一个错误
/registration/ 处的 ValueError 视图 registration.views.login 未返回 HttpResponse 对象。
视图文件是
from django.template import loader
from django.shortcuts import render
from registration.models import Registration
from django.http import HttpResponse
def login(request):
if request.method == 'POST':
user = authenticate(username=request.POST['username'], password=request.POST['password'])
if user is not None:
if user.is_active:
login(request, user)
# success
return HttpResponseRedirect('sucess')
else:
# disabled account
return direct_to_template(request, 'inactive_account.html')
else:
# invalid login
return direct_to_template(request, 'invalid_login.html')
def logout(request):
logout(request)
return direct_to_template(request, 'logged_out.html')
login.html 文件是
<h3>Login</h3>
<form action="/login/" method="post" accept-charset="utf-8">
<label for="username">Username:--</label><input type="text" name="username" value="" id="username" /><br>
<label for="password">Password:-- </label><input type="password" name="password" value="" id="password" />
<p><input type="submit" value="Login →"></p>
</form>