我正在尝试在django中实现密码重置功能,以下是我的代码
urls.py
urlpatterns = patterns('',
url(r'^signup/$', 'accounts.views.signup', name="signup_email"),
url(r'^user/password/reset/$', 'django.contrib.auth.views.password_reset', {'template_name':'accounts/forgot_password.html',\
'post_reset_redirect' : '/user/password/reset/done/'}, name="reset_password"),
url(r'^user/password/reset/done/$', 'django.contrib.auth.views.password_reset_done'),
forgot_password.html
<form accept-charset="UTF-8" action="{% url 'reset_password' %}" class="reset_pass" id="reset_pass" method="post">
{% csrf_token %}
<div class="control-group">
<label class="control-label" for="user_email" style="font-size: 18px; color: #474747">Email</label>
<div class="controls">
<input class="" id="id_email" name="email" type="text" value="">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" value="reset_password" class="btn btn-primary">Send me reset password</button>
</div>
</div>
</form>
所以当我们转到网址user/password/reset/
时会显示forgot_password.html
,当我输入电子邮件并提交表单时,我会收到以下错误
和
模板渲染时出错
In template /home/user/proj/virtualenvironment/apps/pro_utils/accounts/templates/registration/password_reset_email.html, error at line 7
任何人都可以告诉我为什么它在抱怨NoReversemtach
即使我正在使用内置视图?
答案 0 :(得分:2)
您需要在urls.py
中添加该网址+视图,如下所示
url(r'^user/password/reset/confirm/$',
'django.contrib.auth.views.password_reset_confirm'),
它提供了输入新密码的表单。
您可能还需要添加此内容
url(r'^user/password/reset/complete/$',
'django.contrib.auth.views.password_reset_complete'),
答案 1 :(得分:1)
您还可以使用django.contrib.auth.urls
中定义的默认网址
(r'^accounts/', include('django.contrib.auth.urls')),
到urls.py
。
password_reset_confirm
模式需要uidb64
和token
的2个附加参数:
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
'password_reset_confirm',
另见答案:What are the default URLs for Django's User Authentication system?