jinjia2模板默认开启的是自动转义,将一切特殊字符进行转义,所以浏览器无法解析传入的html

 

@app.route('/about/<int:id>')
def about(id):
    about = models.Blog.query.filter_by(id=id).first()
  
return render_template("about.html", about=about)
{% extends 'base.html'  %}
{% block main %}
<main class="r_box">
     <div class="about">
{{ about.content | safe }} </div> </main> {% endblock %}

about.content 是<p>test</p><p></test>

只要输出的时候:

about.content | safe ,标记改数据为安全的时候,模板才不会将内容进行转义

相关文章:

  • 2021-12-18
  • 2022-12-23
  • 2021-09-20
  • 2021-06-29
  • 2022-02-11
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
猜你喜欢
  • 2021-05-27
  • 2022-12-23
  • 2021-06-12
  • 2022-12-23
  • 2021-10-29
  • 2021-08-31
相关资源
相似解决方案