我是新来的Django,我试图添加用户身份验证到一个简单的应用程序。我正在使用Django 1.9,我正在尽可能简单地做到这一点。登录和注销工作,但使用“更改密码”,我得到一个NoReverseMatch的password_change_done错误。django password_change noreversematch
从我的urls.py
app_name = 'league'
urlpatterns = [
url(r'^$', views.index, name='index'),
url('^', include('django.contrib.auth.urls')),
]
在/league/templates/league/index.html,我有:
<a href="{% url 'league:login' %}">Login</a>
<a href="{% url 'league:logout' %}">Logout</a>
<a href="{% url 'league:password_change' %}">Change Password</a>
<a href="{% url 'league:password_change_done' %}">Change Password Done</a>
我在创建这些文件/联盟/模板/注册/ 。 password_change_form.html和password_change_done.html目前什么都不做,它们只包含一个显示的字符串。
- 的login.html
- logged_out.html
- password_change_form.html
- password_change_done.html
当我点击 “更改密码” 链接,我得到:
NoReverseMatch at /league/password_change/
Reverse for 'password_change_done' with arguments'()' and keyword arguments '{}' not found.
我知道“更改密码已完成”链接是sil但是我添加了它来查看会发生什么。它工作正常。当我点击它时,按预期显示password_change_done.html。
下面是当我点击“更改密码”链接的堆栈跟踪:
Environment:
Request Method: GET
Request URL: http://localhost:8000/league/password_change/
Django Version: 1.9.2
Python Version: 3.4.3
Installed Applications:
['league.apps.LeagueConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'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 "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
76. return view(request, *args, **kwargs)
File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/contrib/auth/views.py" in inner
49. return func(*args, **kwargs)
File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/contrib/auth/views.py" in password_change
308. post_change_redirect = reverse('password_change_done')
File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/core/urlresolvers.py" in reverse
600. return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix
508. (lookup_view_s, args, kwargs, len(patterns), patterns))
Exception Type: NoReverseMatch at /league/password_change/
Exception Value: Reverse for 'password_change_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
我发现计算器类似案件,其中包括this one.
我改变了我的urls.py这样:
url(r'^password_change/$',
auth_views.password_change,
{'current_app': 'league'},
name='password_change'),
url(r'^password_change_done/$',
auth_views.password_change_done,
{'current_app': 'league'},
name='password_change_done'),
但它没有区别,我仍然得到NoReverseMatch错误。
任何想法我做错了“更改密码”?
谢谢, 迈克
这让我走了,谢谢!我添加了password_change_done的URL声明,并且它工作得很好。 – Mike