首页 > 其他 > 详细

django自定义用户认证模块

时间:2020-05-01 16:32:29      阅读:52      评论:0      收藏:0      [点我收藏+]

技术分享图片

class CustomAuth(ModelBackend):
    def authenticate(self, request, username=None, password=None, **kwargs):
        try:
            user = UserProfile.objects.get(Q(username=username) | Q(mobile=username))
            if user.check_password(password):
                return user
        except Exception as e:
            return None

  

技术分享图片

AUTHENTICATION_BACKENDS = [
    ‘apps.users.views.CustomAuth‘,   # 引用自定义的认证后端
]

  

 

官方文档:https://docs.djangoproject.com/en/2.2/topics/auth/customizing/

 

django自定义用户认证模块

原文:https://www.cnblogs.com/xiaohaodeboke/p/12813464.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!