gpt4 book ai didi

python - 使用 django 的默认 View 在 django 中重置密码时出现 NoReverseMatch 异常

转载 作者:行者123 更新时间:2023-12-01 04:12:23 26 4
gpt4 key购买 nike

当我使用“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'),

]

最佳答案

您的password_reset_confirm网址模式已过期。它从 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 模式中使用 View 而不是字符串。

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

确保您

关于python - 使用 django 的默认 View 在 django 中重置密码时出现 NoReverseMatch 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34751358/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com