这是我的登录视图:
def sign_in(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:
login(request, user)
redirect('/')
else:
# Return a 'disabled account' error message
return render_to_response('message.html', {...})
else:
# Return an 'invalid login' error message.
???
else:
form = LoginForm()
return render(request, 'accounts/login.html', {
'form': form,
})
这是我的 LoginForm 类:
class LoginForm(forms.Form):
username = forms.CharField(required=True, max_length=30)
password = forms.CharField(required=True, widget=forms.PasswordInput(), max_length=128)
缺少的部分是# Return an 'invalid login' error message.
???
如何重新显示带有无效登录错误消息的表单?