问题描述
可能重复:
django:将模板变量渲染为html
我正在开发一个 django 站点,并且我有一个字符串变量,其中包含 html 标记.我需要将该字符串作为模板上的 html 代码读取.
I am developing a django site and I have a string variable which has html tags in it. I need that string to be read as html code on my template.
例如,如果我有一个字符串变量
For instance if I have a string variable
description = "<ul><li>abc</li><li>def</li><li>ghi</li></ul>"
description = "<ul><li>abc</li><li>def</li><li>ghi</li></ul>"
当我在模板中调用这个字符串变量时,我希望它显示为
When I call this string variable in my template, I would like it to be displayed as
- abc
- 定义
- ghi
目前它按原样显示字符串.
Currently it shows the string as it is.
非常感谢您对此提供任何帮助.
I would really appreciate any help with this.
推荐答案
{{ description | safe }}
https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#safe
更多
https://docs.djangoproject.com/en/dev/topics/模板/#automatic-html-escaping
这篇关于在 django 模板中将字符串转换为 html 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!




大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)