只是另一个 NoReverseMatch 在/accounts/password/reset/问题。
我尝试了很多不同的解决方案,但没有任何效果对我有用。
顺便说一句,如果我尝试使用不在数据库中的随 secret 码,我不会收到任何错误。

姜戈 1.6

错误

NoReverseMatch at /accounts/password/reset/
Reverse for 'django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments '{u'uidb64': 'Mg', u'token': u'3vb-60fc793f1a685844bbe1'}' not found. 0 pattern(s) tried: []

Error during template rendering

In template /home/jr/Documents/python/amapp1/local/lib/python2.7/site-packages/django/contrib/admin/templates/registration/password_reset_email.html, error at line 7
Reverse for 'django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments '{u'uidb64': 'Mg', u'token': u'3vb-60fc793f1a685844bbe1'}' not found. 0 pattern(s) tried: []

urls.py
from django.conf.urls import patterns, url
from django.contrib.auth.views import login, password_reset, password_reset_confirm, password_reset_done, password_reset_complete

url(r'^password/reset/$', 'django.contrib.auth.views.password_reset',
 {'post_reset_redirect' : '/accounts/password/reset/done/'}),
url(r'^password/reset/done/$', 'django.contrib.auth.views.password_reset_done'),
url(r'^password/reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm',
 {'post_reset_redirect' : '/accounts/password/done/'}),
url(r'^password/done/$', 'django.contrib.auth.views.password_reset_complete'),

password_reset_email.html
{{ protocol}}://{{ domain }}{% url 'django.contrib.auth.views.password_reset_confirm' uidb64=uid token=token %}

它是 password_reset_email.html 模板中的链接,因为我确实收到了电子邮件,如果删除链接,也不会出错。

最佳答案

将 password_reset_email.html 中的 url 更改为:

{{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}

这是在 docs 中的做法

关于python - Django NoReverseMatch at/accounts/password/reset/用于密码重置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26045185/

10-12 22:11