Django,无法解析html标记 [英] Django, html tags not interpreted

查看:70
本文介绍了Django,无法解析html标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从django项目的数据库中加载文本以在模板中显示它.

I am loading a text from the DB of a django project to display it in the template.

在数据库中存储的文本中,我添加了一些HTML标记,但似乎浏览器无法解释此html标记.

In the text stored within the data base, I added some HTML tags but it seems like the browser cannot interprete this html tags.

这是我的模板:

<div>
  <!-- body_text = "<strong>Hello</strong> word"  -->
  {{ entry.body_text }} 
</div>

我得到了原始文本:< strong>你好</strong>单词而不是

And I got the raw text: <strong>Hello</strong> word instead of

<strong>Hello</strong> word

我做错了什么?

推荐答案

如果您不希望转义HTML,请使用 safe 过滤器:

If you don't want your HTML to be escaped, use safe filter:

{{ entry.body_text|safe }}

关于安全过滤器的Django文档.

这篇关于Django,无法解析html标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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