Django 错误 - 使用参数 '()' 和关键字参数 ' 反转 'password_reset_confirm'

Django Error - Reverse for 'password_reset_confirm' with arguments '()' and keyword arguments '

我正在尝试在我的应用程序中创建重置密码功能,并在我的 urls.py.

中添加了以下行

urls.py

url(r'^resetpassword/passwordsent/$', 'django.contrib.auth.views.password_reset_done', name='password_reset_done'),
    url(r'^resetpassword/$', 'django.contrib.auth.views.password_reset'),
    url(r'^reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm'),
    url(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),

但是当我在重置密码时输入我的电子邮件 ID 时,它显示了一个我无法理解的错误。 Reverse for 'password_reset_confirm' with arguments '()' and keyword arguments '我已经阅读了一些建议,但 none 正在发挥作用。谁能帮我解决这个错误?

见下图:

Django 需要知道如何从 url 模板标签中使用的名称解析 URL。您应该将名称添加到此行:

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

所以它变成了:

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

在此处查看有关反向分辨率的更多信息:

https://docs.djangoproject.com/en/1.8/topics/http/urls/#reverse-resolution-of-urls

使用以下方法修复错误。您的正则表达式太严格,最多只允许 20 个字符。参考以下link获取更多信息https://code.djangoproject.com/ticket/31913.

我将 url 更改为以下内容并且有效 path(r'reset/<uidb64>/<token>/',

<uidb64>/<token>/ 将“//”添加到您的 url,它应该可以工作