gpt4 book ai didi

python - 反转 'password_change_done',参数 '()' 和关键字参数 '{}' 未找到。 0 种模式已尝试 : []

转载 作者:行者123 更新时间:2023-11-28 17:21:42 25 4
gpt4 key购买 nike

我在 Django 中收到以下错误。与参数“()”和关键字参数“{}”未找到的“password_change_done”相反。尝试了 0 种模式:[]。我不太确定为什么会收到此错误。

网址.py

from django.conf.urls import url
from django.contrib.auth import views as auth_views
from . import views

urlpatterns = [
url(r'^login/$', auth_views.login, name='login'),
url(r'^logout/$', auth_views.logout, name='logout'),
url(r'^logout-then-login/$', auth_views.logout_then_login, name="logout_then_login"),
url(r'^$', views.dashboard, name='dashboard'),

#change password urls
url(r'^password-change/$', auth_views.password_change, name='password_change'),
url(r'^password-change/done/$', auth_views.password_change_done, name='password_change_done'),
]

回溯: 环境:

Request Method: GET
Request URL: http://127.0.0.1:8000/account/password-change/

Django Version: 1.10.4
Python Version: 3.5.2
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'whitenoise',
'crispy_forms',
'business',
'account']
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.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/Users/Tommy/Desktop/django/directory/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
39. response = get_response(request)

File "/Users/Tommy/Desktop/django/directory/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)

File "/Users/Tommy/Desktop/django/directory/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/Users/Tommy/Desktop/django/directory/lib/python3.5/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
76. return view(request, *args, **kwargs)

File "/Users/Tommy/Desktop/django/directory/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)

File "/Users/Tommy/Desktop/django/directory/lib/python3.5/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)

File "/Users/Tommy/Desktop/django/directory/lib/python3.5/site-packages/django/contrib/auth/views.py" in inner
47. return func(*args, **kwargs)

File "/Users/Tommy/Desktop/django/directory/lib/python3.5/site-packages/django/contrib/auth/views.py" in password_change
308. post_change_redirect = reverse('password_change_done')

File "/Users/Tommy/Desktop/django/directory/lib/python3.5/site-packages/django/urls/base.py" in reverse
91. return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))

File "/Users/Tommy/Desktop/django/directory/lib/python3.5/site-packages/django/urls/resolvers.py" in _reverse_with_prefix
392. (lookup_view_s, args, kwargs, len(patterns), patterns)

Exception Type: NoReverseMatch at /account/password-change/
Exception Value: Reverse for 'password_change_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

我要打开的页面的 html

{% extends "base.html" %}
{% load crispy_forms_tags %}

{% block title %}Change Your Password{% endblock %}

{% block content %}
<div class="offset-md-3 col-md-6">
<h1>Change Your Password</h1>
<p>Use the form below to change your password.</p>
<form action="." method="post">
{{form|crispy}}
{% csrf_token %}
</form>
</div>
{% endblock %}

最佳答案

由于您在应用程序的 url.py 中添加了 password_change,因此您应该使用 post_change_redirect 参数指定包含应用程序名称的 post_change url:

url(r'^password-change/$', password_change, {'post_change_redirect': 'account:password_change_done'}, name='password_change'),
url(r'^password-change/done/$', password_change_done, name='password_change_done'),

其中 account 是应用程序 url 的命名空间。

关于python - 反转 'password_change_done',参数 '()' 和关键字参数 '{}' 未找到。 0 种模式已尝试 : [],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41214510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com