在我的django模型中,我必须将html数据存储为类似
的字符串 item = RocketuItem(text=text, page_url=url, page_number=page_number, page_down=page_down)
和text =
<section> <h2>Object-oriented Python and Beginner Django</h2> <ul>
当我在模板中拉这个时,我使用..
{% for page in pages %}
<div>{{ page.page_url|safe }}</div>>
<div>
{{ page.text|safe }}
我使用安全,因为它显示$ lt等[基本上'&lt;'转换为&amp; lt,如果我不使用它] 这是我在页面上的输出中看到的
<section> <h2>Object-oriented Python and Beginner Django</h2> <ul>
我真正想要的是将'text'的代码作为div的一部分,以便它能够很好地获得格式并显示..
Object-oriented Python and Beginner Django
我该怎么做..
答案 0 :(得分:0)
答案 1 :(得分:0)
safe
过滤器应足以在最新版本的Django
中将文本呈现为html。尝试使用:
{% autoescape off %} {{ content }} {% end autoescape %}
标记并查看它是否适合您。