怎么确保在网页中插入含有html标签内容,页面还能正常显示,html标签,最近在折腾python


最近在折腾python web的flask,碰到如下问题: 我有一个template叫index.html, 在body中包含如下内容

 <div class="span9" id="news_loadding">     {% for item in news %}        <div class="weibo-text">{{ item['description'] }}</div>     {% endfor %} </div>

现在变量{{ item['description'] }}的内容如下

现任<font color="RED">澳洲</font>总理吉拉德在澳大利亚工党领袖选举中输给陆克文。<br />

如何插入该变量的内容后,html正常解析这些标签??向大家求教 目前,{{ item['description'] }}的内容直接显示在页面上,也就是说<font..., <br/>这些HTML标签原原本本的显示出来了,而没有解析。

jinja 为了安全起见默认会对 html 进行转义,添加 safe 参数即可

{{ item['description']|safe }}

编橙之家文章,

评论关闭