如何将“app\u settings”的“AuthenticationMethod”设置为“username\u email”?

2024-04-25 21:47:47 发布

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

在我的项目中,我使用allauth,在我的自定义LoginSerializer的validate方法中:

    if 'allauth' in settings.INSTALLED_APPS:
        from allauth.account import app_settings

        # Authentication through email
        if app_settings.AUTHENTICATION_METHOD == app_settings.AuthenticationMethod.EMAIL:
            user = self._validate_email(email, password)

        # Authentication through username
        if app_settings.AUTHENTICATION_METHOD == app_settings.AuthenticationMethod.USERNAME:
            user = self._validate_username(username, password)

你看有app_settings.AuthenticationMethod.EMAILapp_settings.AuthenticationMethod.USERNAME类型。你知道吗

我阅读了源代码,找到了:

enter image description here

还有另一种类型USERNAME_EMAIL

class AppSettings(object):

    class AuthenticationMethod:
        USERNAME = 'username'
        EMAIL = 'email'
        USERNAME_EMAIL = 'username_email'

我在哪里可以设置allauth使用AuthenticationMethod.USERNAME\u电子邮件?你知道吗


Tags: appauthenticationifsettingsemailusernamevalidatemethod
1条回答
网友
1楼 · 发布于 2024-04-25 21:47:47

settings.py中配置ACCOUNT_AUTHENTICATION_METHOD它将工作:

ACCOUNT_AUTHENTICATION_METHOD = 'username_email'

请小心,不要设置AUTHENTICATION_METHOD。你知道吗

您可以在official document中找到更多详细信息。你知道吗

相关问题 更多 >