authenticate()始终返回None Python 3 Django 1.5
我已使用authenticate()始终返回None Python 3 Django 1.5,python,django,authentication,Python,Django,Authentication,我已使用create\u user()成功创建了一个用户,该用户可以登录到管理部分。但是,在my views.py中编写代码以便用户可以在其他任何地方登录,这是行不通的。这是我正在使用的代码,即使用户名和密码绝对正确,authenticate()仍然返回None def dologin(request): usrnym = request.POST['usrnym'] psswrd = request.POST['usrpass'] usr = authenticate(
create\u user()
成功创建了一个用户,该用户可以登录到管理部分。但是,在my views.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)
我可能错了,但不是应该错吗
usr=authenticate(username=usrnym,password=psswrd)
它应该是用户名而不是用户,这是一个语法错误
usr = authenticate(username = usrnym, password = psswrd)
它应该是用户名而不是用户,这是一个语法错误
usr = authenticate(username = usrnym, password = psswrd)
哼!我讨厌问这样愚蠢的问题。我的大脑在过去的一天左右都快崩溃了。Django让我头晕。谢谢现在可以了,不用担心。当你可以有一双额外的眼睛来查看你的代码时,它总是很有帮助的!我讨厌问这样愚蠢的问题。我的大脑在过去的一天左右都快崩溃了。Django让我头晕。谢谢现在可以了,不用担心。当你可以有一双额外的眼睛来查看你的代码时,它总是很有帮助的。谢谢!不知怎的,我完全忽略了那个细节,在过去的两个小时里我一直在仔细研究这个代码。很抱歉,我没有将你的评论标记为答案,直到看到另一条评论后我才看到。谢谢!不知怎的,我完全忽略了那个细节,在过去的两个小时里我一直在仔细研究这个代码。很抱歉,我没有将你的评论标记为答案,直到我看到另一条评论后,我才看到它。