找不到参数“()”和关键字参数“{}”的“密码更改完成”的反转

2024-09-27 07:34:15 发布

您现在位置:Python中文网/ 问答频道 /正文

背景

我试图在Django项目中自定义身份验证视图,但似乎无法运行自定义的password_change视图。我使用Django 1.8.2和Python 2.7。

我的模块urls.pyuserauth如下所示:

from django.conf.urls import patterns, include, url

urlpatterns = patterns('django.contrib.auth.views',
    url(r'^login/$', 'login', {'template_name': 'userauth/login.html'},
        name='userauth_login'),
    url(r'^logout/$', 'logout', {'next_page': '/'},
        name='userauth_logout'),
    url(r'^password-change/$', 'password_change',
        {'template_name': 'userauth/password_change_form.html'},
        name='userauth_password_change'),
    url(r'^password-change-done/$', 'password_change_done',
        {'template_name': 'userauth/password_change_done.html'},
        name='userauth_password_change_done'),
)

这在mainurls.py中被引用如下:

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^account/', include('userauth.urls')),
]

我的模板userauth/password_change_form.html

{% extends "base.html" %}

{% block title %}{{ block.super }} - Change Password{% endblock %}

{% block toggle_login %}{% endblock %}

{% block content %}
<form action="{% url 'userauth_password_change' %}" method="post" accept-charset="utf-8">
  {{ form.as_p }}
  {% csrf_token %}
  <input type="submit" value="Change password"/>
</form>
{% endblock %}

以及userauth/password_change_done.html的模板

{% extends "base.html" %}

{% block title %}{{ block.super }} - Password change successful{% endblock %}

{% block content %}
<p>Your password has been changed successfully.</p>
<a href="{% url 'products_product_index' %}">Back to your Account</a>
{% endblock %}

问题

当我打开'password_change_done'页面(at/account/password change done)时,一切都很好。

但是在'password-change'(/accunt/password change)处,我得到了这个错误:

NoReverseMatch at /account/password-change/

Reverse for 'password_change_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

我试过的

我不知道为什么会这样。

  1. 我试着从url 'userauth_password_change'中删除单引号
  2. 我确保password-change-done页面存在于url.py中并且可用
  3. 我阅读了Reverse for '*' with arguments '()' and keyword arguments '{}' not foundDjango: Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not foundDjango change_password NoReverseMatch at /accounts/password/change/上的解决方案(还有一些,我在那里尝试了所有的解决方案,但在我自己的代码中找不到问题)

感谢您的帮助。谢谢您!


Tags: djangonamepyformurlhtmlloginpassword

热门问题