如何在Django认证中配置双认证用户模式

2024-06-28 10:51:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用django的身份验证来登录用户。但是我有两个模型,其中authenticate方法将检查用户凭证。一个是ApplicationUser,另一个是SystemUser我做了一个,效果很好:

模型.py

class UserManager(BaseUserManager):
    def create_user(self, email, password=None):
        """
        Creates and saves a User with the given username and password.
        """
        ....
        return user

    def create_superuser(self, email, password):        
        ...
        return user


class ApplicationUser(AbstractBaseUser):
    application_user_id = models.AutoField(primary_key=True)
    ....
    ....

视图.py

^{pr2}$

我解决了这个问题,得到了here,但我无法想出解决办法。在

我的问题:

  1. 我如何指定两个AUTH_USER_MODEL,到目前为止我已经设置好了 ApplicationUser作为AUTH_USER_MODEL

  2. 即使我指明 这两个AUTH_USER_MODELauthenticate或{}是如何工作的 知道在哪里(ApplicationUserSystemUser)匹配凭据并为用户创建会话 相应地


Tags: 用户py模型selfauthmodeldefcreate