在学习别人的袋面的时候,抄了下面一段代码:
class CustomBackend(ModelBackend):
"""
自定义用户验证规则
"""
def authenticate(self, username=None, password=None, **kwargs):
try:
user = User.objects.get(
Q(username=username) | Q(mobile=username))
# django的后台中密码加密:所以不能password==password
# UserProfile继承的AbstractUser中有def check_password(self,
# raw_password):
if user.check_password(password):
return user
except Exception as e:
return None
然后在settings.py中配置:
AUTHENTICATION_BACKENDS = (
'user.views.CustomBackend',
)
再然后就登陆一直抱用户名或密码错误:
![](https://img.haomeiwen.com/i8199259/4031635189baabb3.png)
检查了许久,才发现,登录验证被修改了(之前代码抄过来就忘了(灬ꈍ ꈍ灬),教训……)
找到问题就好修改了,要不直接把上面的取消,要不把验证中的内容修改一下
网友评论