我已经自定义了我的 Django 重置密码模板,但是每次我发送重置密码电子邮件时,它们都以 html 的形式发送,尚未转换为字符串 一个很好的例子是
<p>please go to the following page and choose a new password:</p>
<h5>
http://127.0.0.1:8000/api/accounts/reset/MQ/52b-204bbaf9b94c438dff7e/
Thanks for using our site!
</h5>
这就是我的收件箱的显示方式。我的代码如下:urls.py
urlpatterns = [
path('signup', UserCreate.as_view(), name='signup'),
path('login', UserLoginAPIView.as_view(), name='login'),
re_path(r'^activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
activate, name='activate'),
path('password/reset', PasswordResetView.as_view(),
{'template_name': 'templates/registration/password_reset_email.html',
'html_email_template_name': 'templates/registration/password_reset_email.html',
'subject_template_name': 'templates/registration/password_reset_subject.txt',
'from_email': config('EMAIL_HOST_USER'),
'extra_email_context': 'templates/registration/password_reset_email.txt',
},
name='password_reset'),
path('password/reset/done', PasswordResetDoneView.as_view(),
{'template_name': 'templates/registration/password_reset_done.html'},
name='password_reset_done'),
re_path(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$', PasswordResetConfirmView.as_view(),
name='password_reset_confirm'),
path('reset/done/', PasswordResetCompleteView.as_view(), name='password_reset_complete'),
]
password_reset.html
<p>please go to the following page and choose a new password:</p>
<h5>
http://127.0.0.1:8000{% url 'password_reset_confirm' uidb64=uid token=token %}
Thanks for using our site!
</h5>
我已经研究了如何将 html 转换为字符串但没有成功