python django用户未使用用户对象进行身份验证

时间:2015-07-10 11:01:18

标签: python django authentication

好的我面临着身份验证的问题

user_profile = UserProfile.objects.get(email="some@email.com")
new_password = form.cleaned_data['new_password']
user_profile.user.set_password(new_password)
user_profile.user.save()
user = authenticate(username=user_profile.user.username, password=new_password)
print(user)

当我打印用户时,它会提供None

为什么没有对用户进行身份验证?

1 个答案:

答案 0 :(得分:0)

django.contrib.auth的身份验证功能会在凭据匹配时返回django.contrib.auth.models.User类的实例,如果不在,则返回无。

我猜不存在您提供的用户名和密码的用户。这就是为什么你得到无。

我建议你去shell并运行:

from django.contrib.auth.models import User
from django.contrib.auth.hashers import make_password
password = make_password("your_password")
user = User.objects.filter(username="username",password=password)

并查看用户持有的内容。