问题
I have the following template called post-macro
, but when I call the macro in the page.html
template, it inserts a string, with quotes, containing the HTML, rather than directly inserting the HTML.
post-macro
:
{% macro postmacro(post) %}
// html here
{% endmacro %}
page.html
:
{% from "post-macro" import postmacro with context %}
{{ postmacro(post) }}
It renders the page like this. Notice the double quotes around the output.
"
html here
"
What do I need to change to get the HTML directly rather than in quotes?
回答1:
Rename the post-macro
template to post-macro.html
and Jinja will render HTML directly.
来源:https://stackoverflow.com/questions/28597537/why-does-this-jinja-macro-render-text-instead-of-html