使用Django的默认视图在Django中重置密码时出现NoReverseMatch异常 [英] NoReverseMatch exception while resetting password in django using django's default views

查看:88
本文介绍了使用Django的默认视图在Django中重置密码时出现NoReverseMatch异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 ResetMyPassword按钮时出现以下错误

I am getting the below error when I am using the 'ResetMyPassword' button

Reverse for 'password_reset_confirm' with arguments '()' and keyword arguments '{'uidb64': b'MTI', 'token': '48i-a406f922c705599d2c1e'}' not found. 1 pattern(s) tried: ['blog/resetpassword/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>,+)/$']

请在下面找到我的urls.py

Please find my urls.py below

from django.conf.urls import url, patterns
from django.contrib.auth.views import *
from . import views

urlpatterns = [
    url(r'^home$', views.home, name = 'blog_home'),
    url(r'^newpost$', views.new_post, name = 'blog_new_post'),
    url(r'^login$', views.login_user, name = 'blog_login'),
    url(r'^logout$', views.logout_user, name = 'blog_logout'),
    url(r'^register$', views.register_user, name = 'blog_register'),
    url(r'^resetpassword/passwordsent/$', password_reset_done, name = 'password_reset_done'),
    url(r'^resetpassword/$', password_reset, name = 'password_reset'),
    url(r'^resetpassword/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>,+)/$', password_reset_confirm, name = 'password_reset_confirm'),
    url(r'^reset/done/$', password_reset_complete, name = 'password_reset_complete'),

]

推荐答案

您的 password_reset_confirm URL模式已过期。它从uidb36更改为uidb64 。应该是:

Your password_reset_confirm URL pattern is out of date. It changed from uidb36 to uidb64 in Django 1.6. It should be:

url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
'django.contrib.auth.views.password_reset_confirm',
name='password_reset_confirm'),

也更新您的密码重置电子邮件模板:

Update your password reset email template as well:

{% url 'password_reset_confirm' uidb64=uid token=token %}

在Django 1.8+中,应在URL模式而不是字符串中使用视图。

In Django 1.8+, you should use the view in your url pattern rather than the string.

from django.contrib.auth.views import password_reset_confirm

urlpatterns = [
    ...
    url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
    password_reset_confirm, name='password_reset_confirm'),
    ...
]

确保您

这篇关于使用Django的默认视图在Django中重置密码时出现NoReverseMatch异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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