[英]How to configure two AUTH_USER_MODEL in Django Authentication
我正在使用django的身份验证来登录用户。 但是我有两个模型,从这里可以使用authenticate
方法检查用户凭据。 一个是ApplicationUser
,另一个是SystemUser
我已经创建了其中一个,它的工作原理如下:
models.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)
....
....
views.py
def login_view(request):
...
user = authenticate(username = email, password = password)
if user is not None:
...
login(request, user)
....
....
我遇到了这个问题,来到了这里,但是我无法解决这个问题。
我的问题:
如何指定两个AUTH_USER_MODEL
,到目前为止,我已经将ApplicationUser
设置为AUTH_USER_MODEL
。
即使我以某种方式指定了两个AUTH_USER_MODEL
, authenticate
或login
功能如何知道在哪里( ApplicationUser
或SystemUser
)匹配凭据并相应地为用户创建会话
在您的settings.py中
AUTH_USER_MODEL = 'yourapp.YouCustomUserModel'
然后让django完成其余的工作。
如果要使用其他用户模型,则需要从所选的AUTH_USER_MODEL
扩展它们
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.