我有这样的登录视图:
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
,我可以显示验证码,但我不知道如何实现它。我怎么能这样做?
答案 0 :(得分:0)
您可以这样设置会话数据中的attempt
变量:
request.session['attempt'] = 1
并将会话用作常规字典,这意味着使用
等工具if 'attempt' in request.session: