简体   繁体   中英

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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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