简体   繁体   English

python / django:如何将json字符串转换为html格式?

[英]python/django: How can I convert json string to html format?

I'm not sure if this is possible, but I really appreciate it if there's such a thing. 我不确定这是否可行,但是如果有这样的事情,我真的很感激。

I have a json object that contains a json string that another program returns which is a html code. 我有一个json对象,其中包含另一个程序返回的json字符串,这是一个html代码。 However, when I render it to the django template, it's just a big trunk of string. 但是,当我将其渲染为Django模板时,它只是一个很大的字符串主干。 I wonder if there's such tool in python/django that can convert a string into "html format" text. 我想知道python / django中是否有这样的工具可以将字符串转换为“ html格式”文本。 Thanks. 谢谢。

Edit: I use json.loads() to load the output of the other program, and extract the useful information, then return it to template. 编辑:我使用json.loads()加载其他程序的输出,并提取有用的信息,然后将其返回到模板。 In template I simply use django template syntax like {{ v.response }} to show it. 在模板中,我仅使用django模板语法(如{{ v.response }}来显示它。 After that the page looks like this: 之后,页面如下所示:

在此处输入图片说明

假设您知道该字符串是安全的,则可以这样标记,以使模板引擎不会自动转义它:尝试{{ v.response|safe }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM