【问题标题】:Django email verification - customize email html & 404 not found accounts/profile/Django 电子邮件验证 - 自定义电子邮件 html & 404 not found accounts/profile/
【发布时间】:2019-08-04 21:02:57
【问题描述】:

我有两个问题。电子邮件验证效果很好,但我想自定义发送给用户的电子邮件。以下是邮件内容:

本地主机您好!

您收到这封电子邮件是因为用户测试已将您的邮件作为 用于连接其帐户的电子邮件地址。

要确认这是正确的,请转到 http://127.0.0.1:8000/rest-auth/registration/account-confirm-email/MTE:1h4DCn:JtkrZ1wkENQIdG8ysIVu7Qx_R44/

感谢本地主机! https://localhost:8000/

如何创建一个 html 文件并在电子邮件中填写我想要发送的内容?那么邮件主题呢?

第二个问题是,当我点击链接时,用户会得到验证,但随后我在 /accounts/profile 上收到 404 错误。

这是我的代码:

from allauth.account.views import confirm_email

urlpatterns = [
        path('accounts/', include('allauth.urls')),
        path('rest-auth/', include('rest_auth.urls')),
        url(r'^rest-auth/registration/account-confirm-email/(?P<key>[-:\w]+)/$', confirm_email),
        path('rest-auth/registration/', include('rest_auth.registration.urls')),
]

我是否必须为 accounts/profile/ 添加一个 url 并创建一个显示电子邮件验证成功的 html 模板?另外,有没有办法将url更改为accounts/verification-success/?

【问题讨论】:

    标签: django-allauth django-rest-auth


    【解决方案1】:

    自定义电子邮件

    您可以在此处找到使用的默认电子邮件模板:https://github.com/pennersr/django-allauth/tree/master/allauth/templates/account/email

    • 主题:email_confirmation_subject.txt
    • 文字邮箱:email_confirmation_message.txt

    您可以像任何其他模板一样在 Django 应用程序中覆盖它们。

    要激活 HTML,您只需添加自己的文件,名称为 email_confirmation_message.html

    您还可以在注册时收到不同的消息,或者只是确认一个电子邮件地址。

    您可以查看code 以了解其工作原理。

    帐户/个人资料/

    当您到达此处时,您已成功登录。但是,您需要自己实现此 URL 的视图,因为此处要显示的内容是特定于项目的。您也可以决定重定向到其他地方:

    https://docs.djangoproject.com/en/dev/ref/settings/#login-redirect-url

    来自https://django-allauth.readthedocs.io/en/latest/faq.html#when-i-attempt-to-login-i-run-into-a-404-on-accounts-profile

    由于您必须自己实施配置文件,您也可以使用accounts/verification-success/

    【讨论】:

    • 谢谢!我实际上只使用 Django 作为我的 react native 应用程序的后端。我感觉这个包主要用于网络?
    • django-rest-auth 是一个纯身份验证 API 包。但它使用 django-allauth。这是一个经典的网络应用程序。
    猜你喜欢
    • 1970-01-01
    • 2019-05-28
    • 2021-05-26
    • 1970-01-01
    • 2016-11-23
    • 1970-01-01
    • 1970-01-01
    • 2014-09-16
    • 1970-01-01
    相关资源
    最近更新 更多