Django:将raw html(从数据库)显示为html,而不是呈现 [英] Django: show raw html (from database) as html, not rendered
问题描述
我已经使用tinymce创建了一个丰富的文本区域。我现在已将其保存到我的数据库,并希望显示它。它被保存在数据库中作为具有标签的html等。要显示它,我尝试过:
在视图中:
content = get_content_from_db()
pre>
render_to_response(template.html,{content:content})
在模板中:
{{content}}
这个标签显示的内容如下:
< strong>我的文字< / strong>
而不是只显示文字为粗体。
我也试过使用逐字标签,但是这个(doh!)显示为:
{{content}}
我该怎么做?我需要保存不同吗?我保存它的方式我保存任何其他TextArea除了字段是一个blob。
解决方案使用
安全
过滤器{{content | safe}}
I have created a rich text area using tinymce. I have now saved this to my database and want to display it. It gets saved in the database as html with tags, etc. To display it I have tried:
In views:
content = get_content_from_db() render_to_response("template.html", {"content":content})
In template:
{{content}}
This shows the content with the tags like so:
<strong>My text</strong>
instead of just displaying the text as bold.
I have also tried using the verbatim tag, but this (doh!) displays as:
{{content}}
How should I do this? Do I need to save it differently? I save it the way I save any other TextArea except the field is a blob.
解决方案Use
safe
filter{{ content|safe }}
这篇关于Django:将raw html(从数据库)显示为html,而不是呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!