【发布时间】:2020-11-13 06:40:05
【问题描述】:
我是 django/python 的新手
我正在尝试更改用户密码,但出现错误
Method Not Allowed (POST): /password_change_done
Method Not Allowed: /password_change_done
[23/Jul/2020 19:11:05] "POST /password_change_done HTTP/1.1" 405 0
这是我的 url 模式,仅用于更改密码:
path('password_change',
auth_views.PasswordChangeView.as_view(template_name='password_change.html'),
name='password_change'),
path('password_change_done',
auth_views.PasswordChangeDoneView.as_view(template_name='password_change_done.html'),
name='password_change_done'),
我的两个用于此操作的 html 页面 我的 html 代码:password_change
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome</title>
</head>
<body>
<h3> Change Password</h3>
<form action="{% url 'password_change_done' %}" method="POST" class="form-signin">{% csrf_token %}
<input name="Old password" class="form_control" placeholder="Old password"
type="password" id=old_password required="true">
<input name="new password" class="form_control" placeholder="new password"
type="password" id=new_password required="true">
<input name="confirm password" class="form_control" placeholder="confirm password"
type="password" id=confirm_password required="true">
<button type="submit">Update</button>
</form>
</body>
</html>
password_chang_done 的 html 代码:
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome</title>
</head>
<body>
<h1>Welcome</h1>
<h2> <img src="{% static 'images/welcome.jpg' %}"> </h2>
<h5>hello,{{request.user.username}}</h5>
<script>
window.alert("password sucessfully changed")
</script>
</body>
</html>
【问题讨论】:
-
您应该向
"{% url 'password_change' %}"视图发出POST 请求。password_change_done是更改成功时的结果。 -
分享你的 password_change_done 控制器。
-
@mursalin:我认为这些是来自
django.contrib.auth.views的那些,但具有更新的模板名称(在.as_view(..)调用中)。 -
将发布请求更改为 password_change 使我保持在同一页面上,并且不会将我重定向到下一页
-
真的,如果您只想使用 bootstrap4 重新设置样式,请保存some pain。
标签: python html django django-forms