python Django重置密码URL NoReverseMatch

时间:2015-01-12 10:03:34

标签: python django

我遇到Django密码重置问题。这是我的urls.py

(r'^resetpassword/passwordsent/$', 'django.contrib.auth.views.password_reset_done', {'template_name':'registration/password_reset_done.html'}),
(r'^resetpassword/$', 'django.contrib.auth.views.password_reset'),
(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm'),
(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),

当我去resetpassword时,我得到了

NoReverseMatch at /resetpassword/
Reverse for 'password_reset_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

如果需要,这是我的追溯:

Request Method: GET
Request URL: http://127.0.0.1:8000/resetpassword/

Django Version: 1.7.1
Python Version: 2.7.8
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'dailyresults',
 'trainingresults',
 'athlete',
 'easy_pdf')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "D:\Programy\Python27\lib\site-packages\django-1.7.1-py2.7.egg\django\core\handlers\base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "D:\Programy\Python27\lib\site-packages\django-1.7.1-py2.7.egg\django\utils\decorators.py" in _wrapped_view
  105.                     response = view_func(request, *args, **kwargs)
File "D:\Programy\Python27\lib\site-packages\django-1.7.1-py2.7.egg\django\contrib\auth\views.py" in password_reset
  146.         post_reset_redirect = reverse('password_reset_done')
File "D:\Programy\Python27\lib\site-packages\django-1.7.1-py2.7.egg\django\core\urlresolvers.py" in reverse
  551.     return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "D:\Programy\Python27\lib\site-packages\django-1.7.1-py2.7.egg\django\core\urlresolvers.py" in _reverse_with_prefix
  468.                              (lookup_view_s, args, kwargs, len(patterns), patterns))

Exception Type: NoReverseMatch at /resetpassword/
Exception Value: Reverse for 'password_reset_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

使用url函数代替简单元组并设置网址的name

from django.conf.urls import url
...
url(r'^resetpassword/passwordsent/$',
                'django.contrib.auth.views.password_reset_done',
                {'template_name':'registration/password_reset_done.html'},
                name="password_reset_done"),