Django的观点.PasswordResetView发送的电子邮件不是html类型



我正在尝试重置密码,但电子邮件看起来不像htmlurls.py

url(r'^password_reset/$', auth_views.PasswordResetView.as_view(
template_name='account/password_reset_form.html',
email_template_name='account/password_reset_email.html',
success_url='/account/password_reset_done'
), name='password_reset'),

password_reset_email.html

<p>您收到这封邮件是因为您正在重置密码,如果非本人操作请勿略</p>
<p>请点击下面网站设置一个新密码:</p>
<a href="{{ protocol }}://{{ domain }}{% url 'account:password_reset_confirm' uidb64=uid token=token %}"></a>
<p>用户名:{{ user.get_username }}</p>
<p>感谢使用我们的网站</p>
<p>晶晨羽毛球协会</p>

设置.py

# 将发送的邮件直接显示在控制台
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# smpt服务地址
EMAIL_HOST = 'smtp.qq.com'
EMAIL_PORT = 25
# 发送邮件的邮箱
EMAIL_HOST_USER = 'xxxx33928@qq.com'
# 在邮箱中设置的客户端授权密码
EMAIL_HOST_PASSWORD = 'xxxxgorrbecd'
# 收件人看到的发件人
DEFAULT_FROM_EMAIL = 'xxx3928@qq.com'
SERVER_EMAIL ='xxx3928@qq.com'

myemail

<p>您收到这封邮件是因为您正在重置密码,如果非本人操作请勿略</p>
<p>请点击下面网站设置一个新密码:</p>
<a href="http://127.0.0.1:8000/account/password_reset_confirm/MQ/5i4-0dfc61d517145c2857dd/"></a>
<p>用户名:coco</p>
<p>感谢使用我们的网站</p>
<p>晶晨羽毛球协会</p>

urls.py

from django.contrib import admin
from django.urls import path
from django.conf.urls import url, include
from django.contrib.auth import views as auth_views
from .views import UserListView, RegisterView
urlpatterns = [
url(r'^$', UserListView.as_view(), name='index'),
url(r'^login/$', auth_views.LoginView.as_view(template_name='account/login.html'), name='login'),
url(r'^logout/$', auth_views.LogoutView.as_view(template_name='account/logout.html'), name='logout'),
url(r'^register/$', RegisterView.as_view(), name='register'),
url(r'^password_change/$', auth_views.PasswordChangeView.as_view(
template_name='account/password_change_form.html',
success_url='/account/password_change_done/'
), name='password_change'),
url(r'^password_change_done/$', auth_views.PasswordChangeDoneView.as_view(
template_name='account/password_change_done.html',
), name='password_change_done'),
url(r'^password_reset/$', auth_views.PasswordResetView.as_view(
template_name='account/password_reset_form.html',
html_email_template_name='account/password_reset_email.html',
success_url='/account/password_reset_done'
), name='password_reset'),
url(r'^password_reset_done/$', auth_views.PasswordResetDoneView.as_view(
template_name='account/password_reset_done.html'
), name='password_reset_done'),
path('password_reset_confirm/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(
template_name='account/password_reset_confirm.html',
success_url='/account/password_reset_complete'
), name='password_reset_confirm'),
url(r'password_reset_complete/$', auth_views.PasswordResetCompleteView.as_view(
template_name='account/password_reset_complete.html'
), name='password_reset_complete'),
]

错误模板呈现过程中出错在template/home/coco/.virtualenvs/badmintion/lib/python3.6/site-packages/django/control/admin/templates/registration/password_reset_email.html中,第6行出现错误

找不到"password_reset_confirm"的反向password_reset_confirm'不是有效的视图函数或模式名称。

它看起来像一个txt。标签无效。我的问题在哪里。我该怎么修。

PasswordResetView[Django doc]中的email_template_name参数用于文本电子邮件。您应该使用html_email_template_name参数(因此使用html_前缀(:

url(
r'^password_reset/$',
auth_views.PasswordResetView.as_view(
template_name='account/password_reset_form.html',
html_email_template_name='account/password_reset_email.html',
email_template_name='account/password_reset_email.html',
success_url='/account/password_reset_done'
), name='password_reset'
),

相关内容

  • 没有找到相关文章

最新更新