【问题标题】:NoReverseMatch exception while resetting password in django using django's default views使用 django 的默认视图在 django 中重置密码时出现 NoReverseMatch 异常
【发布时间】:2016-04-17 12:32:14
【问题描述】:

当我使用“ResetMyPassword”按钮时出现以下错误

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

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'),

]

【问题讨论】:

  • 请给我们看一个带有表格的模板。
  • token 的模式使用逗号而不是点。

标签: python django


【解决方案1】:

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

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

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

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

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

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

确保你

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-24
    • 2013-09-21
    • 1970-01-01
    • 2016-06-15
    • 1970-01-01
    • 2017-09-07
    • 1970-01-01
    相关资源
    最近更新 更多