在jinja2模板中转义jinja2语法


88

我从Flask的Jinja2模板提供动态页面。现在,我在脚本标签内定义客户端模板,例如Jinja2克隆Nunjucks。问题是,客户端模板具有类似语法<% %>瓶的Jinja2的解释,而不是可以解释渲染的逐字

如何使整个脚本块按原样呈现?


注: 神社做到这一点不同于树枝
dreftymac

Answers:


192

您可以禁用{% raw %}块内标签的解释:

{% raw %}

Anything in this block is treated as raw text,
including {{ curly braces }} and
{% other block-like syntax %}

{% endraw %}

请参阅模板文档的转义部分

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.