gpt4 book ai didi

python - Django rest auth 电子邮件而不是用户名

转载 作者:太空狗 更新时间:2023-10-29 20:12:13 24 4
gpt4 key购买 nike

我有一个 Django 项目,我在其中使用 Django-rest-auth 进行身份验证。我想使用带密码的电子邮件来验证用户而不是用户名+密码。

我的 settings.py 中有以下设置,但它对我没有任何作用:

REST_SESSION_LOGIN = True
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_AUTHENTICATION_METHOD = 'EMAIL'
ACCOUNT_EMAIL_VERIFICATION = 'optional'

我怎样才能实现它?

最佳答案

以下设置有效:

#This is required otherwise it asks for email server
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# ACCOUNT_EMAIL_REQUIRED = True
# AUTHENTICATION_METHOD = 'EMAIL'
# ACCOUNT_EMAIL_VERIFICATION = 'optional'

ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False

#Following is added to enable registration with email instead of username
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
"django.contrib.auth.backends.ModelBackend",

# `allauth` specific authentication methods, such as login by e-mail
"allauth.account.auth_backends.AuthenticationBackend",
)

关于python - Django rest auth 电子邮件而不是用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36698456/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com