在jinja2模板中逃避jinja2语法 [英] Escape jinja2 syntax in a jinja2 template

查看:154
本文介绍了在jinja2模板中逃避jinja2语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Flask中的Jinja2模板提供动态页面。现在我正在定义客户端模板,比如Jinja2-clone Nunjucks。问题是,客户端模板的语法如<%%> ,Flask的 Jinja2解释器可能会解释而不是逐字呈现



如何让整个脚本块逐字呈现?

解决方案



  =lang-none prettyprint-override>  {%raw%} 

此块中的任何内容都被视为原始文本,
包括{{花括号}}和
{%其他块状语法%}

{%endraw%}

请参阅模板文档的 Escaping 部分


I serve dynamic pages from Jinja2 templates in Flask. Now I am defining client-side templates in say, Jinja2-clone Nunjucks inside a script tag. Problem is, the client-side templates has syntax like <% %> that Flask's Jinja2 interpreter may interpret instead of rendering verbatim.

How can I make the entire block of scripts render verbatim?

解决方案

You can disable interpretation of tags inside a {% raw %} block:

{% raw %}

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

{% endraw %}

See the Escaping section of the template documentation.

这篇关于在jinja2模板中逃避jinja2语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆