Django 1.0,使用默认密码重置
我正在尝试使用Django自带的密码重置功能,但它的文档不是很好。现在我用的是Django 1.0,结果总是出现这个错误:
Caught an exception while rendering: Reverse for 'mysite.django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments ...
在我的url配置文件中,我有这样的内容:
#django.contrib.auth.views
urlpatterns = patterns('django.contrib.auth.views',
(r'^password_reset/$', 'password_reset', {'template_name': 'accounts/registration/password_reset_form.html', 'email_template_name':'accounts/registration/password_reset_email.html', 'post_reset_redirect':'accounts/login/'}),
(r'^password_reset/done/$', 'password_reset_done', {'template_name': 'accounts/registration/password_reset_done.html'}),
(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'password_reset_confirm', {'template_name': 'accounts/registration/password_reset_confirm.html', 'post_reset_redirect':'accounts/login/', 'post_reset_redirect':'accounts/reset/done/'}),
(r'^reset/done/$', 'password_reset_complete', {'template_name': 'accounts/registration/password_reset_complete.html'}),
)
问题似乎出在这个文件:
password_reset_email.html
在第7行
{% url django.contrib.auth.views.password_reset_confirm uidb36=uid, token=token %}
我对发生了什么感到困惑,所以任何帮助都非常感谢。
谢谢
4 个回答
2
我花了一个多小时在这个页面和网上的其他页面上尝试各种方法,真是费劲。最后,我发现解决我这个问题的方法是把
{% load url from future %}
从我的 password_reset_email.html 模板的顶部删除掉。
另外,注意一下,网址脚本中的 "uidb36=uid"。这是我完整的 password_reset_email.html 模板,希望能帮到别人节省一些时间:
{% autoescape off %}
You're receiving this e-mail because you requested a password reset for your user account at {{ site_name }}.
Please go to the following page and choose a new password:
{% block reset_link %}
{{ protocol }}://{{ domain }}{% url django.contrib.auth.views.password_reset_confirm uidb36=uid token=token %}
{% endblock %}
Your username, in case you've forgotten:" %} {{ user.username }}
Thanks for using our site!
The {{ site_name }} team
{% endautoescape %}
3
编辑: 我用了你的例子,但不得不改成不使用关键字参数。
{% url django.contrib.auth.views.password_reset_confirm uid, token %}
命名参数是可以用的,只要 uid 和 token 都有定义。如果其中一个没有定义或者是空的,我就会遇到和你一样的错误:
{% url django.contrib.auth.views.password_reset_confirm uidb36=uid, token=token %}
2
我想分享一下我找到的解决办法。问题出在这一行:
{% url django.contrib.auth.views.password_reset_confirm uidb36=uid, token=token %}
我也不太确定为什么会这样,所以我就直接把网址写死了,像这样:
http://mysite.com/accounts/reset/{{uid}}-{{token}}/