找不到"password_reset_confirm".'password_reset_confirm'不是有效的视图函数或模式名称 [英] 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name

查看:60
本文介绍了找不到"password_reset_confirm".'password_reset_confirm'不是有效的视图函数或模式名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到此错误:

在/accounts/password_reset/下的NoReverseMatch/找不到与"password_reset_confirm"相反的字符.'password_reset_confirm'不是有效的视图函数或模式名称

NoReverseMatch at /accounts/password_reset/ Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name

以下是我到目前为止的代码:

The following is my code so far:

from django.conf.urls import url
from . import views
from django.urls import include
from django.contrib.auth import views as auth_views


app_name = 'accounts'

urlpatterns = [
    url(r'^login/$', views.login_view, name='login_view'),
    url(r'^register_view/$', views.register_view, name='register_view'),
    url(r'^logout/$', views.logout_view, name="logout_view"),
    url(r'^profile_view/$', views.profile_view, name="profile_view"),
    url(r'password_change/$',auth_views.PasswordChangeView.as_view(template_name='password_change.html',success_url='/accounts/password_change_done')),
    url(r'password_change_done/',auth_views.PasswordChangeDoneView.as_view(template_name='password_change_done.html')),
    url(r'password_reset/$',auth_views.PasswordResetView.as_view(template_name='registration/password_reset_form.html',email_template_name='registration/password_reset_email.html',subject_template_name='registration/password_reset_email.txt',success_url='/accounts/password_reset_done/',from_email='mpho.maleka3@gmail.com')),
    url(r'password_reset_done/',auth_views.PasswordResetDoneView.as_view(template_name='registration/password_reset_done.html')),
    url(r'password_reset_confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',auth_views.PasswordResetConfirmView.as_view(template_name='registration/password_reset_confirm.html',success_url='/accounts/password_reset_confirm/'), name='password_reset_confirm'),
    url(r'password_reset_complete/',auth_views.PasswordResetCompleteView.as_view(template_name='registration/password_reset_complete.html')),
]

推荐答案

您需要知道django使用默认模板作为电子邮件主题,默认模板为(password_reset_email.html),名称为 password_reset_confirm ,但您使用的是名称空间,即acocunts: password_reset_confirm ,所有您需要做的就是

You need to know that django uses the default template for the email message subject which is (password_reset_email.html) under the name password_reset_confirm, but your are using a namespace, acocunts:password_reset_confirm, all what you need to do is

  1. 使用此attr email_template_name
  2. 覆盖模板路径
  1. Override the template path using this attr email_template_name

auth_views.PasswordResetView.as_view(
  template_name ='accounts/registration/password_reset.html',
  email_template_name = 'accounts/registration/password_reset_email.html'),

  1. settings.py 中设置您的电子邮件配置,以发送电子邮件,而不会收到错误消息(错误编号111),拒绝连接
  1. Set up your email configurations in settings.py to send your email, without getting a error (Errno 111) connection refused

这篇关于找不到"password_reset_confirm".'password_reset_confirm'不是有效的视图函数或模式名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆