通过 POST 的 django-uni-form 帮助程序和 CSRF 标签
我正在使用 django-uni-forms 来显示我的字段,并使用直接来自他们书中的相当基本的示例。
当我使用 渲染表单字段时,一切都按预期工作。
但是,django-uni-form Helpers 允许您使用以下语法生成表单标签(以及其他与 helper 相关的内容) - {% with form.helper as helper %}{% uni_form form helper%}{ %endwith%}
-- 这为我创建了
有人有这方面的经验吗?有没有既定的方法来添加令牌?出于重用的原因,我更喜欢第二种语法。 谢谢!
I'm using django-uni-forms to display my fields, with a rather rudimentary example straight out of their book.
When I render the form fields using <form>{%csrf_tag%} {%form|as_uni_form%}</form>
, everything works as expected.
However, django-uni-form Helpers allow you to generate the form tag (and other helper-related content) using the following syntax -- {% with form.helper as helper %}{% uni_form form helper%}{%endwith%}
-- This creates the <form>
tag for me, so there's nowhere to embed my own CSRF_token. When I try to use this syntax, the form renders perfectly, but without a CSRF token, and so submitting the form fails every time.
Does anyone have experience with this? Is there an established way to add the token? I much prefer the second syntax, for re-use reasons.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你检查过来源吗?它应该已经在那里了。 uni_form 模板标签应自动包含它。
Have you checked the source? It should already be there. The uni_form template tag should include it automatically.
我在 django-uni-form 上遇到了完全相同的问题。如果我使用以下内容,则 csrf 令牌不会显示在
或:
如果我手动包含它,它会起作用:
我找到了 博客文章 概述了如何手动包含 csrf 令牌:
一点也不漂亮,但至少它得到了统一形式工作。
I'm having the exact same problem with django-uni-form. The csrf token does not show up after the
<form>
tag if I use:or:
If I include it manually it works:
I found a blog post that outlines how to include the csrf token manually:
Not at all pretty but at least it gets the uni-form to work.
最简单的解决方案是从 GitHub 安装 django-uni-form,直到 PyPi 上的版本更新到 0.8。
The easiest solution is to install django-uni-form from GitHub until the version on PyPi is updated to 0.8.
使用最新版本的 django-uni-form。它解决了这个问题以及更多问题。
Use the most recent version of django-uni-form. It fixes this and so much more.