这行代码负责发送包含密码重置链接的电子邮件。
path('accounts/password-reset/', auth_views.PasswordResetView.as_view(), name='password_reset'),
然而,这封电子邮件看起来完全无聊,很难在阅读时区分重要部分。
为了吸引用户的注意力并更好地指导他们,我想在此电子邮件正文中添加样式。
可以通过以下几行代码将自定义模板添加到电子邮件中:
...
path('accounts/', include('django.contrib.auth.urls')),
path('accounts/password-reset/', auth_views.PasswordResetView.as_view(html_email_template_name='registration/password_reset_email.html'), name='password_reset'),
...
邮件中重置链接由uidb64值和令牌组成,例如:
localhost:8000/password-reset/calculated_uidb64/calculated_token
什么是将这些值传递给自定义模板
password_reset_email.html
的正确方法?
<a href="{{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}" style=".."> 重置密码 </a>
来添加 URL,你试过了吗?此外,我发现一篇文章可以证明上面分享的答案。请看 http://garmoncheg.blogspot.com/2012/07/django-resetting-passwords-with.html - Hemant