如何在jinja2模板引擎中csrf_token保护? [英] How to csrf_token protection in jinja2 template engine?
本文介绍了如何在jinja2模板引擎中csrf_token保护?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Django模板中,我使用了
< form action =/ usermethod =post> { %csrf_token%}
{{form.as_p | safe}}
< input type =submitvalue =Submit/>
< / form>
但是当我更改为 jinja2模板引擎时出错... / code >:
遇到未知标记'csrf_token'
我的问题: csrf_token保护
在 jinja2
是否需要? >
如果需要,该怎么做?
提前感谢
解决方案
似乎Jinja2的工作方式不同:
使用< input type =hidden name =csrfmiddlewaretokenvalue ={{csrf_token}}>
其中使用的Django模板使用 {%csrf_token%}
来源: http://exyr.org/2010 / Jinja-in-Django /
In Django template I used:
<form action="/user" method="post">{% csrf_token %}
{{ form.as_p|safe }}
<input type="submit" value="Submit" />
</form>
But error when I change to jinja2 template engine
:
Encountered unknown tag 'csrf_token'
My question: csrf_token protection
in jinja2
is required?
If required, how to do this?
Thanks in advance!
解决方案
It seems Jinja2 works differently:
Use <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
where in Django templates you use {% csrf_token %}
source : http://exyr.org/2010/Jinja-in-Django/
这篇关于如何在jinja2模板引擎中csrf_token保护?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文