Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过Django在数据库中保存Html代码_Html_Django_Python 3.x - Fatal编程技术网

如何通过Django在数据库中保存Html代码

如何通过Django在数据库中保存Html代码,html,django,python-3.x,Html,Django,Python 3.x,我想通过django在数据库中保存html代码 在models.py中,我有这个字段 description = models.TextField() 但是当我通过Django Admin在描述字段中保存数据时。它显示这样的数据 <h1>This is example</h1> 这是一个示例 而不是将其转换为html 模板引擎转义html默认值。显示时,必须使用安全标签对其进行过滤 {{ description |safe }} 或者使用自动转义标记 {% aut

我想通过django在数据库中保存
html代码

models.py
中,我有这个字段

description = models.TextField()
但是当我通过Django Admin描述字段中保存数据时。它显示这样的数据

<h1>This is example</h1>
这是一个示例

而不是将其转换为html

模板引擎转义html默认值。显示时,必须使用安全标签对其进行过滤

{{ description |safe }}
或者使用自动转义标记

{% autoescape off %}{{ description }}{% endautoescape %}

我在哪里可以使用这些标签?在view.py或在models.py或在my view.htmlIt中应该在您的视图中。感谢它的工作..我只是将此代码像这样放在view.html中{%autoescape off%}{{object.description | linebreaks}{%endautoescape%}@devdap当您说它应该在您的视图中时需要小心。Django中的视图相当于其他框架中的控制器。所以我会说“它应该在你的模板中,比如template.html”