且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Django的默认视图在Django中重置密码时出现NoReverseMatch异常

更新时间:2023-09-28 21:52:58

您的 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'),
    ...
]

确保您