使用Flask / Jinja2将HTML传递给模板 [英] Passing HTML to template using Flask/Jinja2

查看:216
本文介绍了使用Flask / Jinja2将HTML传递给模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为Flask和SQLAlchemy构建了一个管理员,并且我想使用 render_template 将不同输入的HTML传递给我的视图。模板框架似乎自动转义html,所以所有<'转换为html实体。我如何禁用,以便HTML呈现正确?

I'm building an admin for Flask and SQLAlchemy, and I want to pass the HTML for the different inputs to my view using render_template. The templating framework seems to escape the html automatically, so all <"'> are converted to html entities. How can I disable that so that the HTML renders correctly?

推荐答案

理想的方法是

the ideal way is to

{{ something|safe }}

完全关闭自动转义功能。

than completely turning off auto escaping.

这篇关于使用Flask / Jinja2将HTML传递给模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆