REST身份验证注册后Django不发送电子邮件 [英] Django is not sending email after rest-auth registration
问题描述
在将用户模型更改为使用电子邮件而不是用户名后,访问 rest-auth.registration.views.RegisterView
时电子邮件未发送.
After I changed user model to using email instead of username, email is not sending when I access rest-auth.registration.views.RegisterView
.
我该怎么做才能工作?
我的电子邮件设置为:
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
这是正确的配置,可以在 rest_auth.views.PasswordResetView
上发送电子邮件.
It's correct configuration, sending email on rest_auth.views.PasswordResetView
works fine.
users/urls.py:
app_name = "users"
urlpatterns = [
path("register/", include("rest_auth.registration.urls")),
...
]
config/urls.py:
from allauth.account.views import AccountInactiveView
urlpatterns = [
...
path("api/v1/users/", include("myproject.users.urls")),
# this url is used to generate email content
# https://github.com/Tivix/django-rest-auth/blob/master/demo/demo/urls.py
path("password-reset/<uidb64>/<token>/", TemplateView.as_view(), name="password_reset_confirm")
# for some reason required for rest-auth register view working
path("account-inactive/", AccountInactiveView.as_view(), name="account_inactive"),
]
config/settings.py
ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_USERNAME_REQUIRED = False
访问寄存器视图后,没有错误.创建用户对象,响应(代码201)为:
After accessing register view, there's no error. User object is created and response (code 201) is:
{
"detail": "Verification e-mail sent."
}
但是没有发送电子邮件.
However there's no email sent.
感谢帮助!
推荐答案
我解决了这个问题.发生此问题的原因是 User
模型中 is_active
字段的默认值为 False
.出于某些原因, allauth
和 rest-auth
不允许为不活动的用户发送激活电子邮件.
I solved this problem. The problem occurred because default value for is_active
field in User
model was False
. And for some reason allauth
and rest-auth
do not allow to send activation email for inactive user.
这篇关于REST身份验证注册后Django不发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!