NoReverseMatch:在Django-registration的密码重置表单中?

时间:2022-11-15 10:02:31

I get the following error when I access this URL http://127.0.0.1:8000/accounts/password/reset/

当我访问这个URL http://127.0.1:8000 /account /password/reset/时,会出现以下错误

Request Method: GET
Request URL:    http://127.0.0.1:8000/accounts/password/reset/
Django Version: 1.6.2
Exception Type: NoReverseMatch
Exception Value:    
Reverse for 'password_reset_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

my password_reset_form.html is

我的password_reset_form。html是

{% extends "registration/base.html" %}
{% load i18n %}

{% block breadcrumbs %}<div class="breadcrumbs"></div>{% endblock %}

{% block title %}{% trans "Password reset" %}{% endblock %}

{% block content %}

<h1>{% trans "Password reset" %}</h1>

<p>{% trans "Forgotten your password? Enter your e-mail address below, and we'll e-mail instructions for setting a new one." %}</p>

<form action="" method="post">
    {% csrf_token %}
{{ form.email.errors }}
<p><label for="id_email">{% trans 'E-mail address:' %}</label> {{ form.email }} <input type="submit" value="{% trans 'Reset my password' %}" /></p>
</form>

{% endblock %}

EDIT: I have corrected as suggested by frnhr, but the following error pops up.

编辑:我已经按照frnhr的建议进行了更正,但是出现了以下错误。

TemplateSyntaxError at /accounts/password/reset/
Could not parse the remainder: ',' from 'uid,'
Request Method: POST
Request URL:    http://127.0.0.1:8000/accounts/password/reset/
Django Version: 1.6.2
Exception Type: TemplateSyntaxError
Exception Value:    
Could not parse the remainder: ',' from 'uid,'
Exception Location: /Users/sridhar/Documents/virtualenvs/django/django/lib/python2.7/site-packages/django/template/base.py in __init__, line 577
Python Executable:  /Users/sridhar/Documents/virtualenvs/django/django/bin/python
Python Version: 2.7.5

2 个解决方案

#1


2  

Django-registration has not been made compatible with Djagno 1.6. This patch will fix your problem: https://bitbucket.org/ubernostrum/django-registration/pull-request/63/django-16-compatibility-fix-auth-views/diff

django的注册还没有与Djagno 1.6兼容。这个补丁将解决您的问题:https://bitbucket.org/ubernostrum/django-registration/pull-request/63/django-16兼容性-fix-auth-views/diff

registration/auth_urls.py:

注册/ auth_urls.py:

urlpatterns = patterns('',
                       url(r'^login/$',
                           auth_views.login,
                           {'template_name': 'registration/login.html'},
                           name='auth_login'),
                       url(r'^logout/$',
                           auth_views.logout,
                           {'template_name': 'registration/logout.html'},
                           name='auth_logout'),
                       url(r'^password/change/$',
                           auth_views.password_change,
                           {'post_change_redirect': reverse_lazy('auth_password_change_done')},
                           name='auth_password_change'),
                       url(r'^password/change/done/$',
                           auth_views.password_change_done,
                           name='auth_password_change_done'),
                       url(r'^password/reset/$',
                           auth_views.password_reset,
                           {'post_reset_redirect': reverse_lazy('auth_password_reset_done')},
                           name='auth_password_reset'),
                       url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
                           auth_views.password_reset_confirm,
                           name='auth_password_reset_confirm'),
                       url(r'^password/reset/complete/$',
                           auth_views.password_reset_complete,
                           {'post_reset_redirect': reverse_lazy('auth_password_reset_complete')},
                           name='auth_password_reset_complete'),
                       url(r'^password/reset/done/$',
                           auth_views.password_reset_done,
                           name='auth_password_reset_done'),
)

#2


0  

The error that you get is probably because you might not have set the path to template inside urls.py. Because of that, Django tries using the default registration template, which you won't be able to use if you haven't enabled admin. So the two solutions, If you want to use Django's template for resetting password(or for any other feature that @frnhr has mentioned above add this line to your urls.py :

您得到的错误可能是因为您可能没有在url .py中设置到模板的路径。因此,Django尝试使用默认的注册模板,如果没有启用admin,您将无法使用该模板。因此,如果您想使用Django的模板重新设置密码(或者使用@frnhr在上面提到的任何其他特性),那么这两个解决方案可以将这一行添加到您的url中。py:

url(r'^admin/', include(admin.site.urls))

Or, if you want to use your own templates, add this parameter to the dictionary in the answer above

或者,如果您想使用自己的模板,请在上面的答案中向字典添加此参数

{'template_name' : 'registration/password_reset_form.html' }

which would make it look like,

这会让它看起来像,

url(r'^accounts/password/reset/$',
   auth_views.password_reset,
   {'post_reset_redirect': reverse_lazy('auth_password_reset_done'), 
   'template_name': 'registration/password_reset_form.html'},
   name='auth_password_reset')

hope that helps !

希望会有帮助!

#1


2  

Django-registration has not been made compatible with Djagno 1.6. This patch will fix your problem: https://bitbucket.org/ubernostrum/django-registration/pull-request/63/django-16-compatibility-fix-auth-views/diff

django的注册还没有与Djagno 1.6兼容。这个补丁将解决您的问题:https://bitbucket.org/ubernostrum/django-registration/pull-request/63/django-16兼容性-fix-auth-views/diff

registration/auth_urls.py:

注册/ auth_urls.py:

urlpatterns = patterns('',
                       url(r'^login/$',
                           auth_views.login,
                           {'template_name': 'registration/login.html'},
                           name='auth_login'),
                       url(r'^logout/$',
                           auth_views.logout,
                           {'template_name': 'registration/logout.html'},
                           name='auth_logout'),
                       url(r'^password/change/$',
                           auth_views.password_change,
                           {'post_change_redirect': reverse_lazy('auth_password_change_done')},
                           name='auth_password_change'),
                       url(r'^password/change/done/$',
                           auth_views.password_change_done,
                           name='auth_password_change_done'),
                       url(r'^password/reset/$',
                           auth_views.password_reset,
                           {'post_reset_redirect': reverse_lazy('auth_password_reset_done')},
                           name='auth_password_reset'),
                       url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
                           auth_views.password_reset_confirm,
                           name='auth_password_reset_confirm'),
                       url(r'^password/reset/complete/$',
                           auth_views.password_reset_complete,
                           {'post_reset_redirect': reverse_lazy('auth_password_reset_complete')},
                           name='auth_password_reset_complete'),
                       url(r'^password/reset/done/$',
                           auth_views.password_reset_done,
                           name='auth_password_reset_done'),
)

#2


0  

The error that you get is probably because you might not have set the path to template inside urls.py. Because of that, Django tries using the default registration template, which you won't be able to use if you haven't enabled admin. So the two solutions, If you want to use Django's template for resetting password(or for any other feature that @frnhr has mentioned above add this line to your urls.py :

您得到的错误可能是因为您可能没有在url .py中设置到模板的路径。因此,Django尝试使用默认的注册模板,如果没有启用admin,您将无法使用该模板。因此,如果您想使用Django的模板重新设置密码(或者使用@frnhr在上面提到的任何其他特性),那么这两个解决方案可以将这一行添加到您的url中。py:

url(r'^admin/', include(admin.site.urls))

Or, if you want to use your own templates, add this parameter to the dictionary in the answer above

或者,如果您想使用自己的模板,请在上面的答案中向字典添加此参数

{'template_name' : 'registration/password_reset_form.html' }

which would make it look like,

这会让它看起来像,

url(r'^accounts/password/reset/$',
   auth_views.password_reset,
   {'post_reset_redirect': reverse_lazy('auth_password_reset_done'), 
   'template_name': 'registration/password_reset_form.html'},
   name='auth_password_reset')

hope that helps !

希望会有帮助!