[英]authenticate() Always Returns None
I've successfully created a user with create_user()
, and the user can log into the admin section. 我已经使用create_user()
成功创建了一个用户,该用户可以登录admin部分。 BUT, making code in my views.py so the user can log in anywhere else, isn't working. 但是无法在我的views.py中编写代码,以便用户可以在其他任何地方登录。 Here's the code I'm using, and even when the username & password are definitely correct, authenticate()
still returns None
. 这是我正在使用的代码,即使用户名和密码绝对正确, 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)
它应该是用户名而不是用户,它是一个语法错误
usr = authenticate(username = usrnym, password = psswrd)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.