我有一个这样的登录视图:
def login_backend(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
state = "Username or Password Incorrect!"
if user is not None:
login(request, user)
return HttpResponseRedirect('/overview/')
else:
captcha = CaptchaField()
return render_to_response('login_backend.html', {'state':state,
'captcha':captcha }, context_instance=RequestContext(request))
else:
return render_to_response('login_backend.html', context_instance=RequestContext(request))
现在,如果用户多次出错,则会显示验证码。但是,我只想在用户输入错误密码超过 3 次时才显示验证码。我想我可以跟踪用户尝试,如果attempt > 3
,我可以显示验证码,但我不知道如何实现它。我怎样才能做到这一点?