简体   繁体   English

output 到 html 导致 JSON 格式干净

[英]output to html results in JSON format clean

I have a django app that is executing some python scripts and returning results to webpage.... unfortunately the results that are in JSON format look nasty as hell and hard to read.. I am using Visual Studio Code and using the Terminal in that the JSON output is lovely and nice to read which is not good for this.... Anyone know a way to present the results in nice standard JSON Format on my webpage我有一个 django 应用程序正在执行一些 python 脚本并将结果返回到网页....不幸的是,JSON 格式的结果看起来很讨厌,而且在终端中很难阅读。我正在使用终端JSON output 很可爱,读起来很舒服,但这不利于这个....任何人都知道一种方法可以在我的网页上以漂亮的标准 JSON 格式呈现结果

from django.shortcuts import render
import requests
import sys
from subprocess import run, PIPE

def button(request):
    return render(request,'homepage.html')

def external(request):
 out=run([sys.executable,'//home//testuser//data-extract.py'],shell=False,stdout=PIPE)
json.dumps(out, indent=4, sort_keys=True)
    print(out)
    return render(request,'homepage.html',{'data':out})

try to do this at frontend side尝试在前端执行此操作

html html

<pre id="json"></pre>

javascript javascript

 var data = { "data": { "study":"mca" }, "name": "lbvasoya", "country": "india", "id": 50 } document.getElementById("json").innerHTML = JSON.stringify(data,undefined,2)
 <pre id='json'></pre>

document.getElementById("json").innerHTML = JSON.stringify({{ data }}, undefined, 2);

go through this link JSON.stringify use try and let me know go 通过此链接JSON.stringify 使用尝试让我知道

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

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