无法将参数从 html 传递到视图函数
Cannot pass arguments from html to view function
我已经为这个问题苦思了一天了。
我正在使用 Django password_reset_confirm
视图来处理来自用户的密码更改请求。
我收到 screenshot 中所示的错误。
Reverse mismatch for 'password_reset_confirm'
这是我的 html,它呈现表单。
<div>
<h1></h1>
<form id='reset-password-form' action="{% url 'password_reset_confirm' uidb64=uidb64 token=token %}" method="post">
{% csrf_token %}
{{form|foundation }}
{{title}}
{{validlink}}
<div id='submit-button'>
<input type="submit" id='submit-reset-form'>
</div>
</form>
</div>
url映射是这样的:
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',password_reset_confirm, {'set_password_form':ResetPasswordForm,'template_name':'email/password_reset/password_enternew_password.html',}
,name='password_reset_confirm')
谁能告诉我,错误在哪里?
uidb64
和 token
不会传递给模板上下文,因此您不能在 url 标记中使用它们。
最简单的解决方法是从表单中删除 action 属性。这将防止反向匹配错误,并且表单将提交到当前 url,这是正确的。
如果您查看 master 分支中 django.contrib.admin
应用程序包含的 password reset confirm template 的代码,您会发现它没有 action 属性。 Django 的早期版本有 action=""
,但这在 HTML5.
中无效
我已经为这个问题苦思了一天了。
我正在使用 Django password_reset_confirm
视图来处理来自用户的密码更改请求。
我收到 screenshot 中所示的错误。
Reverse mismatch for 'password_reset_confirm'
这是我的 html,它呈现表单。
<div>
<h1></h1>
<form id='reset-password-form' action="{% url 'password_reset_confirm' uidb64=uidb64 token=token %}" method="post">
{% csrf_token %}
{{form|foundation }}
{{title}}
{{validlink}}
<div id='submit-button'>
<input type="submit" id='submit-reset-form'>
</div>
</form>
</div>
url映射是这样的:
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',password_reset_confirm, {'set_password_form':ResetPasswordForm,'template_name':'email/password_reset/password_enternew_password.html',}
,name='password_reset_confirm')
谁能告诉我,错误在哪里?
uidb64
和 token
不会传递给模板上下文,因此您不能在 url 标记中使用它们。
最简单的解决方法是从表单中删除 action 属性。这将防止反向匹配错误,并且表单将提交到当前 url,这是正确的。
如果您查看 master 分支中 django.contrib.admin
应用程序包含的 password reset confirm template 的代码,您会发现它没有 action 属性。 Django 的早期版本有 action=""
,但这在 HTML5.