尝试更改应用密码后,我收到此错误消息。
您是否知道导致此路线失败的原因是什么?
实际上,它正在更改密码,但它不会呈现成功模板" password_change_done.html"。
谢谢!
应用/ urls.py
from django.contrib.auth import views as auth_views
from django.urls import path
from . import views
app_name = 'account'
urlpatterns = [
# path('login/', views.user_login, name='login'),
path('', views.dashboard, name='dashboard'),
# login / logout urls
path('login/', auth_views.LoginView.as_view(template_name='registration/login.html'), name='login'),
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
path('logout-then-login/', auth_views.logout_then_login, name='logout_then_login'),
# change password urls
path('password-change/', auth_views.PasswordChangeView.as_view(), name='password_change'),
path('password_change/done/', auth_views.PasswordChangeDoneView.as_view(), name='password_change_done'),
]
错误消息
# NoReverseMatch at /account/password-change/
# Reverse for 'password_change_done' not found. 'password_change_done' is not a valid view function or pattern name.
# Request Method: POST
# Request URL: http://localhost:8000/account/password-change/
# Django Version: 2.0.4
# Exception Type: NoReverseMatch
# Exception Value:
# Reverse for 'password_change_done' not found. 'password_change_done' is not a valid view function or pattern name.
# Exception Location: C:\env\django_social_website\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix, line 632
# Python Executable: C:\env\django_social_website\Scripts\python.exe
# Python Version: 3.6.3
# Python Path:
# ['C:\\Projects\\django_social_website',
# 'C:\\env\\django_social_website\\Scripts\\python36.zip',
# 'C:\\ProgramData\\Anaconda3\\DLLs',
# 'C:\\ProgramData\\Anaconda3\\lib',
# 'C:\\ProgramData\\Anaconda3',
# 'C:\\env\\django_social_website',
# 'C:\\env\\django_social_website\\lib\\site-packages',
# 'C:\\env\\django_social_website\\lib\\site-packages\\setuptools-28.8.0-py3.6.egg',
# 'C:\\env\\django_social_website\\lib\\site-packages\\pip-9.0.1-py3.6.egg']
# Server time: Thu, 5 Apr 2018 21:34:22 +0000
应用/模板/注册/ password_change_form.html
{% extends "base.html" %}
{% block title %}Change your password{% endblock %}
{% block content %}
<h1>Change your password</h1>
<p>Use the form below to change your password.</p>
<form action="." method="post">
{{ form.as_p }}
{% csrf_token %}
<p><input type="submit" value="Change"></p>
</form>
{% endblock %}
应用/模板/注册/ password_change_done.html
{% extends "base.html" %}
{% block title %}Password changed{% endblock %}
{% block content %}
<h1>Password changed</h1>
<p>Your password has been successfully changed.</p>
{% endblock %}
感谢您的帮助!
答案 0 :(得分:1)
我认为这里的问题是,正如Tobit提示的那样,你的网址正在使用名为for x in lst1:
if x.startswith(input):
expect_output = x
的应用程序命名空间。这是由account
中app_name = 'account'
的存在所定义的。
查找urls.py
视图时,PasswordChangeView
不期望命名空间。但是,您可以通过指定明确password_change_done
属性来覆盖urls.py
中的内容:
success_url
有关命名空间的更多信息:https://docs.djangoproject.com/en/2.0/topics/http/urls/#url-namespaces-and-included-urlconfs