Why does this Jinja macro render text instead of HTML?

我是研究僧i 提交于 2020-01-05 08:06:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!