我不断收到此错误:
在/ accounts / password_reset /下的NoReverseMatch / 找不到“ password_reset_confirm”的反向键。 'password_reset_confirm'不是有效的视图函数或模式名称
以下是我到目前为止的代码:
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')),
]
答案 0 :(得分:0)
要使Django使用您应用的registration/password_reset_form.html'
模板,您需要在django.contrib.admin
设置中将该应用移至 INSTALLED_APPS
。
请注意,Django很难通过密码重置视图来使用名称空间。修复此NoReverseMatch
后,您可能会发现必须修复类似的错误。将您的密码重置URL模式移动到没有名称空间的urls.py
可能会更容易。
答案 1 :(得分:0)
您需要知道django使用电子邮件主题的默认模板(名称为password_reset_confirm
的(password_reset_email.html),但是您使用的是命名空间acocunts:password_reset_confirm
,所有您需要做的是
email_template_name
覆盖模板路径auth_views.PasswordResetView.as_view(
template_name ='accounts/registration/password_reset.html',
email_template_name = 'accounts/registration/password_reset_email.html'),