django自定义用户认证模块

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

  

django自定义用户认证模块

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

  

 

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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-14
  • 2021-12-14
  • 2021-11-02
  • 2022-01-13
猜你喜欢
  • 2021-10-30
  • 2021-07-11
  • 2021-06-04
  • 2021-10-08
  • 2022-12-23
  • 2021-10-26
  • 2022-12-23
相关资源
相似解决方案