我在accounts / urls.py中有以下网址配置:
url(r'^password/change/$', 'django.contrib.auth.views.password_change',
{'template_name': 'change_password.html'}, name='password_change'),
url(r'^password/change/done/$', 'django.contrib.auth.views.logout_then_login',
name='password_change_done'),
但如果我拨打密码更改网址,我会收到以下内容
错误:NoReverseMatch at / accounts / password / change / Reverse for 带有参数'()'和关键字参数'{}'的'password_change_done' 未找到。尝试了0种模式:[]
如果用户修改了密码,则会将其注销并重新登录。
非常感谢。
编辑,追溯
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/password/change/
Django Version: 1.7
Python Version: 3.4.1
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'widget_tweaks',
'djangular',
'djcelery',
'accounts',
'system_utils',
'alert_system',
'proj',
'django_cleanup')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/Users/peter/Projekte/proj-hoster/proj-hoster-env3/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/peter/Projekte/proj-hoster/proj-hoster-env3/lib/python3.4/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
76. return view(request, *args, **kwargs)
File "/Users/peter/Projekte/proj-hoster/proj-hoster-env3/lib/python3.4/site-packages/django/utils/decorators.py" in _wrapped_view
105. response = view_func(request, *args, **kwargs)
File "/Users/peter/Projekte/proj-hoster/proj-hoster-env3/lib/python3.4/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
22. return view_func(request, *args, **kwargs)
File "/Users/peter/Projekte/proj-hoster/proj-hoster-env3/lib/python3.4/site-packages/django/contrib/auth/views.py" in password_change
261. post_change_redirect = reverse('password_change_done')
File "/Users/peter/Projekte/proj-hoster/proj-hoster-env3/lib/python3.4/site-packages/django/core/urlresolvers.py" in reverse
546. return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/Users/peter/Projekte/proj-hoster/proj-hoster-env3/lib/python3.4/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix
463. (lookup_view_s, args, kwargs, len(patterns), patterns))
Exception Type: NoReverseMatch at /accounts/password/change/
Exception Value: Reverse for 'password_change_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
答案 0 :(得分:2)
密码更改完成的参考之一'有破折号,另一个有下划线。它很可能与此有关!
答案 1 :(得分:1)
我意识到这是一个非常旧问题,但我昨天也遇到了同样的错误。我认为名称空间是问题所在。一旦你对网址命名空间,他们都需要以命名空间的名称(在你的情况下"帐户")和冒号为前缀。如果您查看password_change
视图的代码,则会(有条件地)根据' password_change_done'的网址重定向。由于该网址没有使用您的命名空间进行修饰,因此无法找到它。删除命名空间,确保您的网址引用不再具有它,您应该没问题。