如何通过Django将HTML代码保存在数据库中 [英] How to save Html code in database through Django
本文介绍了如何通过Django将HTML代码保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过Django在数据库中保存 html代码
。
I want to save html code
in database through django.
在模型中.py
我有此字段
description = models.TextField()
但是当我通过 Django Admin 将数据保存在说明字段中时。它显示这样的数据
But when i save data in description field through Django Admin. It display data like this
<h1>This is example</h1>
而不是将其转换为html。 这里的出场
rather then converting it in html. Here's the Out Put
推荐答案
模板引擎转义html默认值。
Template engine escaping html default. You have to filter it with safe tag when you showing.
{{ description |safe }}
或使用自动转义标记
{% autoescape off %}{{ description }}{% endautoescape %}
这篇关于如何通过Django将HTML代码保存在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文