-->

how do I include quoted HTML in a Tornado Template

2019-01-23 14:32发布

问题:

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>

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.

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

Is there the equivalent in Tornado Templates?

回答1:

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

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.