背景
我想自定義一個Django項目認證的看法,但我似乎無法得到自定義password_change視圖來運行。我使用Django 1.8.2和Python 2.7。反向的「password_change_done」與參數「()」和關鍵字參數「{}」未找到
我的模塊userauth
的urls.py
如下所示:
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'),
)
這主要urls.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 %}
模板
和模板fo [R 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'
頁(在/帳號/密碼轉換完成),然後一切都很好。
但在'password-change'
(/ accunt /密碼更改)我得到這個錯誤:
NoReverseMatch at /account/password-change/
Reverse for 'password_change_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
我試過
我不知道,爲什麼這應該發生。
- 我試圖從
url 'userauth_password_change'
- 去除單引號我確信在urls.py存在
password-change-done
頁面,並提供 - 我在Reverse for '*' with arguments '()' and keyword arguments '{}' not found,Django: Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found,Django change_password NoReverseMatch at /accounts/password/change/閱讀解決方案(多了幾個,我嘗試了所有的解決方案,但我無法在自己的代碼中找到問題)
任何幫助表示讚賞。謝謝!
當我將'name ='userauth_password_change_done''的名稱更改爲'name ='password_change_done''時,它可以工作。這是爲什麼?有人可以解釋嗎? – Rias