簡體   English   中英

REST身份驗證注冊后Django不發送電子郵件

[英]Django is not sending email after rest-auth registration

將用戶模型更改為使用電子郵件而不是用戶名后,當我訪問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"),
]

配置/ 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)為:

{
  "detail": "Verification e-mail sent."
}

但是,沒有發送電子郵件。

感謝幫助!

我解決了這個問題。 發生問題的原因是User模型中is_active字段的默認值為False 出於某種原因, allauthrest-auth不允許發送非活動用戶的激活電子郵件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM