Flask 的 Jinja 在 'strong' 元素中嵌套一些渲染元素
Flask's Jinja nesting some rendered elements in 'strong' elements
我遇到了 Jinja 的奇怪行为。我制作了一个动态烧瓶路线,所以我制作了一个 jinja 模块化模板,它只是一个 for 循环,为我提供给 Jinja 的某些数据(在字典中)中存在的每个 article
创建一个元素,模板看起来像这样:
{% for theme in article_data %}
{% for article in theme["article"] %}
{% if article["main"] == 1 %}
<div style="background-image: url('{{article['content']['image1']}}');" class="theme-item-bg frow space-between">
{% endif %}
{% endfor %}
<div class="wrapper-row space-between pinkfilter">
<div class="uB theme-item-text">{{theme["name"]}}</div>
<div class="pageChanger waves-effect waves-light btn uL primaryB" page="/nos-articles/{{theme['name']}}" title="{{theme['name']}}">Voir plus d'articles</div>
</div>
</div>
{% endfor %}
它在我的大部分页面上都能正常工作,但有一个页面有一个非常奇怪的行为,Jinja 正确呈现其中一篇文章并将其他文章嵌套在 strong
元素中。
用于呈现页面的数据具有相同的结构并且被正确解析。
有没有办法防止 Jinja 在 strong
元素中嵌套内容?
theme["name"]
中必须有一些 html(通过使用 theme["name"]|escape
转义来修复它),或者 <strong>
标签在您的模板中没有关闭。
Jinja 不会随机插入 html 标签,但浏览器会在尝试解析和修复损坏的 html 代码时插入
我遇到了 Jinja 的奇怪行为。我制作了一个动态烧瓶路线,所以我制作了一个 jinja 模块化模板,它只是一个 for 循环,为我提供给 Jinja 的某些数据(在字典中)中存在的每个 article
创建一个元素,模板看起来像这样:
{% for theme in article_data %}
{% for article in theme["article"] %}
{% if article["main"] == 1 %}
<div style="background-image: url('{{article['content']['image1']}}');" class="theme-item-bg frow space-between">
{% endif %}
{% endfor %}
<div class="wrapper-row space-between pinkfilter">
<div class="uB theme-item-text">{{theme["name"]}}</div>
<div class="pageChanger waves-effect waves-light btn uL primaryB" page="/nos-articles/{{theme['name']}}" title="{{theme['name']}}">Voir plus d'articles</div>
</div>
</div>
{% endfor %}
它在我的大部分页面上都能正常工作,但有一个页面有一个非常奇怪的行为,Jinja 正确呈现其中一篇文章并将其他文章嵌套在 strong
元素中。
用于呈现页面的数据具有相同的结构并且被正确解析。
有没有办法防止 Jinja 在 strong
元素中嵌套内容?
theme["name"]
中必须有一些 html(通过使用 theme["name"]|escape
转义来修复它),或者 <strong>
标签在您的模板中没有关闭。
Jinja 不会随机插入 html 标签,但浏览器会在尝试解析和修复损坏的 html 代码时插入