我已经成功地用create_user()
创建了一个用户,该用户可以登录到管理部分。但是,在我的视图.py所以用户可以在其他任何地方登录,但不工作。下面是我使用的代码,即使用户名和密码绝对正确,authenticate()
仍然返回None
。在
def dologin(request):
usrnym = request.POST['usrnym']
psswrd = request.POST['usrpass']
usr = authenticate(user=usrnym,password=psswrd)
if usr is not None:
if usr.is_active:
login(request, usr)
# redirect to success page
else:
pass
# redirect to a 'disabled account' error message
else:
# return an 'invalid login' error message
errmsg = "Invalid login. Password and username did not match."
template = loader.get_template('fsr/loginform.html')
context = RequestContext(request, {
'title': "Login Page",
'error': errmsg,
'usr': usrnym,
'pwd': psswrd,
'usra': usr,
})
return HttpResponse(template.render(context))
它应该是用户名而不是用户它的语法错误
我可能错了,但这不是应该的吗?在
usr = authenticate(username=usrnym,password=psswrd)
相关问题 更多 >
编程相关推荐