如何在 Tornado 模板中包含引用的 HTML? [英] how do I include quoted HTML in a Tornado Template?

查看:41
本文介绍了如何在 Tornado 模板中包含引用的 HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Tornado 模板,我的一个字段是一个字符串,其中引用了 HTML 标签,例如<p>太阳能</p>

I'm using Tornado Templates and one of my fields is a string that has HTML tags quoted in it, e.g. <p>Solar power</p>

当我将其渲染到模板中时,标签会被逐字引用,而不是被视为标签.{{quoted_html }}所以它看起来和上面的一样,p 标签可见.

When I render it into the template, the tags are quoted verbatim instead of treated as tags. {{ quoted_html }} So it looks exactly as above with the p tag visible.

在其他模板系统中,{{ = foo}} 逐字呈现 foo,但 {{html foo}} 将标签视为标签.

In other templating systems, {{ = foo}} renders foo verbatim, but {{html foo}} treats the tags as tags.

Tornado 模板中是否有等价物?

Is there the equivalent in Tornado Templates?

推荐答案

{% raw foo %}, 在 Tornado 2.0+ 中.

{% raw foo %}, in Tornado 2.0+.

如果您在模板中使用大量表达式执行此操作,则可以将 {% autoescape None %} 指令添加到模板的开头,然后添加 {{ foo }} 不会被转义.

If you do that with a lot of expressions in a template, you can add the {% autoescape None %} directive to the beginning of the template, after which {{ foo }} will not be escaped.

这篇关于如何在 Tornado 模板中包含引用的 HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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