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

问题描述

我从 Flask 中的 Jinja2 模板提供动态页面.现在我在脚本标签中定义客户端模板,比如 Jinja2-clone Nunjucks.问题是,客户端模板的语法类似于 <% %>Flask 的 Jinja2 解释器可能会解释而不是渲染逐字.

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?

推荐答案

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

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 语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:58
查看更多