我正在尝试使用Django内置视图来重置密码,但最终会出错。我已完成以下步骤: 1.在URLs.py中:
url(r'^password_reset/$', auth_views.password_reset,{'email_template_name':'registration/password_reset_email.html','subject_template_name':'registration/password_reset_subject.txt','post_reset_redirect':'main:password_reset_done','from_email':'something@gmail.com',},name='password_reset'),
url(r'^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(),{'success_url':'passwordresetcomplete'}, name='password_reset_confirm' ),
url(r'^password_reset/done/$', auth_views.password_reset_done, {'template_name': 'registration/password_reset_done.html'}, name='password_reset_done'),
url(r'^reset/confirm/done/$', auth_views.password_reset_complete, name='password_reset_complete'),
我还在 appname / templates / registration / 中添加了我的自定义html文件,html文件是:
现在会发生以下情况:当我转到http://127.0.0.1:8000/password_reset/时,它会要求提供电子邮件地址。在为用户输入电子邮件后,它说我们已经向您发送了一个链接,我在电子邮件中看到了该链接。当我点击链接时,会打开一个页面并要求输入新密码和密码确认。当我点击提交按钮时,我可以看到密码确实已更改,但我没有被定向到html页面,而是出现错误。这是
NoReverseMatch at /reset/confirm/MQ/set-password/
Reverse for 'password_reset_complete' not found. 'password_reset_complete' is not a valid view function or pattern name.
Request Method: POST
Request URL: http://127.0.0.1:8000/reset/confirm/MQ/set-password/
Django Version: 1.11.2
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'password_reset_complete' not found. 'password_reset_complete' is not a valid view function or pattern name.
Python Version: 2.7.12
答案 0 :(得分:0)
默认情况下出现错误的链接将在项目urls.py中出现,而不是在apps:urls.py中,尝试将其放入project.urls.py中并运行代码