【问题标题】:Django: Reverse for 'password_reset_complete' not foundDjango:找不到'password_reset_complete'的反向
【发布时间】:2018-01-28 06:16:58
【问题描述】:

我正在尝试使用 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 文件是:

  • password_reset_complete.html
  • password_reset_email.html
  • password_reset_confirm.html
  • password_reset_form.html
  • password_reset_done.html
  • password_reset_subject.txt

现在发生的事情是:当我转到 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

【问题讨论】:

标签: passwords reset


【解决方案1】:

默认情况下,您遇到错误的链接在您的项目 urls.py 中而不是在应用程序中:urls.py 尝试将其放入 project.urls.py 并运行代码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-18
    • 1970-01-01
    • 1970-01-01
    • 2010-10-12
    • 2013-10-05
    • 2018-06-07
    • 2020-01-02
    相关资源
    最近更新 更多