python - Django在rest-auth注册后不发送电子邮件
问题描述
在我将用户模型更改为使用电子邮件而不是用户名后,当我访问rest-auth.registration.views.RegisterView
.
我应该怎么做才能工作?
我的电子邮件设置是:
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
这是正确的配置,发送电子邮件rest_auth.views.PasswordResetView
工作正常。
我的代码:
用户/urls.py:
app_name = "users"
urlpatterns = [
path("register/", include("rest_auth.registration.urls")),
...
]
配置/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"),
]
配置/设置.py
ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_USERNAME_REQUIRED = False
访问寄存器视图后,没有错误。用户对象被创建并且响应(代码 201)是:
{
"detail": "Verification e-mail sent."
}
但是没有发送电子邮件。
感谢帮助!
解决方案
我解决了这个问题。出现问题是因为模型中is_active
字段的默认值为. 并且由于某种原因,不允许为非活动用户发送激活电子邮件。User
False
allauth
rest-auth
推荐阅读
- java - 在同一字符串的不同部分使用替换
- redux - How to integrate Redux DevTools with ReactOnRails
- julia - Closure, anonymous function, why not being the values when they were created
- docker - 使用 Dockerfile 安装的依赖项在后续管道步骤中无法访问。如何启用?
- json - 如何使用 Circe 将空对象插入 JSON?
- c++ - libc++ 的 std::is_literal_type 是如何工作的?
- tensorflow - Tensorflow: Modify datapoints used in loss function evaluation after each gradient step using tf optimizer
- angular - How to use gzipper package in angular 7?
- javascript - 如何在不使用 ajax 硬刷新的情况下多次发出请求
- python - 生成字符串列表的所有排列