首页 文章

Django错误:反向'password_reset_confirm'没有找到参数

提问于
浏览
0

我正在使用Django 1.11来构建用户帐户应用程序 . 我的帐户应用的网址与下面的代码1一样 . 我还有一个模板/注册文件夹和几个模板文件:enter image description here

输入电子邮件地址后,我收到了以下链接的电子邮件:http://127.0.0.1:8000/account/password-reset/confirm/MQ/4ra-66d3672f1d340589fbf9/

我点击上面的链接,浏览器重定向到这个链接:http://127.0.0.1:8000/account/password-reset/confirm/MQ/set-password/

并且错误提示:

NoReverseMatch at / account / password-reset / confirm / MQ / set-password /

反向'password_reset_confirm',未找到任何参数 . 尝试了1种模式:['account/password-reset/confirm/(?P[-\w]+)/(?P[-\w]+)/$']请求方法:GET请求URL:http://127.0.0.1:8000/account/password-reset/confirm/MQ/set-password/ Django版本:1.11.7异常类型:NoReverseMatch异常值:
反向'password_reset_confirm',未找到参数 . 1种模式尝试过:['account/password-reset/confirm/(?P[-\w]+)/(?P[-\w]+)/$']

请帮我解决这个问题 . 看来点击链接后,Django无法在templates / registration文件夹下呈现password_reset_confirm.html .

代码1:

# restore password urls
    url(r'^password-reset/$', auth_views.PasswordResetView.as_view(), name='password_reset'),
    url(r'^password-reset/done/$', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),
    url(r'^password-reset/confirm/(?P<uidb64>[-\w]+)/(?P<token>[-\w]+)/$',
        auth_views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
    url(r'^password-reset/complete/$',
        auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),

2 回答

  • 0

    Django的错误消息是,您的代码已尝试将 password_reset_confirm 反转为其url,但您尚未提供url模式所需的 uid64token 参数 . 您应该找到执行 reverse() 的代码部分并更新它以提供参数:

    reverse('password_reset_confirm',args=(uid64, token))
    
  • 0

    urls.py:

    path('accounts/reset_password_confirm/<uidb64>/<token>/', PasswordResetConfirmView.as_view(), name='reset_password_confirm'),
    

    如上所述更改URL对我有用 . 虽然,我仍然没有收到电子邮件 . 错误消失了 .

相关问题