python - 通过 jinja 变量发送和渲染 HTML 语法
问题描述
我需要一些复杂的操作来在我的front-end
. 但是由于我找不到在我的jinja
or中运行递归的任何方法front-end
,我采取一种方法在我的中创建一个字符串views.py
并在其中HTML syntax
呈现它们front-end
以获得所需的输出,例如(例如,这里我跳过原来复杂的字符串,因为不需要它):
在views.py
:
test = "<h2>Hi This is from django</h2><ol><li>abc</li><li>mno</li><li>xyz</li></ol>"
mydict={
'test' : test,
}
return render(request, 'app\index.html', mydict)
在index.html
:
<div class="container-fluid">
{{ test }}
</div>
我希望使用此代码的输出是:
嗨,这是来自 django
- 美国广播公司
- mno
- xyz
但是得到的输出是:
<h2>Hi This is from django</h2><ol><li>abc</li><li>mno</li><li>xyz</li></ol>
Please suggest to me, is there any way to render the jinja
string variable along with the effect of HTML
in my front-end
? If not then how can I take an approach to render any tree dynamically in my front-end
where the level, leaf node, intermediate node, etc all info come from the database.
解决方案
You can use the django-template-filter safe for this.
{{ test | safe }}
推荐阅读
- node.js - mongoose 实时批量插入
- r - 在 Shinyproxy 的 docker 映像中安装预编译的 r 包时出错
- performance - gitlab接口性能慢
- javascript - Cheerio:循环遍历子元素并调用 html()
- python - 带有标签框的 tkinter 页面布局
- php - PHP解码base64 API对数组的响应
- javascript - 如何在 Nextjs、Reactjs 中的 getInitialProps 之前渲染组件
- r - 使用自写函数时小标题和数据帧的区别
- python - Python:'if...or'条件中的监护人参数
- django - Nginx build_absolute_uri 后面的 Django 返回 http://host/