3

I am trying to implement password reset funcitonality in django and below are my codes

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>

so when we go to the url user/password/reset/ a forgot_password.html is displaying, and when i entered the email and submitted the form i am getting the below errors

enter image description here

and

Error during template rendering

In template /home/user/proj/virtualenvironment/apps/pro_utils/accounts/templates/registration/password_reset_email.html, error at line 7

enter image description here

Can any one please let me know why it is complaining NoReversemtach even though i am using builtin views ?

4

2 回答 2

2

您需要添加该 url+viewurls.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'),
于 2013-09-10T10:48:28.513 回答
1

您还可以使用定义的默认网址django.contrib.auth.urls,包括

(r'^accounts/', include('django.contrib.auth.urls')),

到你的urls.py.

password_reset_confirm模式需要 2 个附加参数uidb64token

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',

另请参阅此处的答案:Django's User Authentication system 的默认 URL 是什么?

于 2014-05-06T14:52:34.453 回答