gpt4 book ai didi

python - 使用 django 模板将 json 填充为 html

转载 作者:太空宇宙 更新时间:2023-11-03 12:41:44 24 4
gpt4 key购买 nike

为了更好地调试我的 api,我想创建一个调试页面,逐行显示响应 json obj 的所有详细信息。我认为这可以通过代码或 django 模板来完成。最简单的方法是什么?

https://developers.facebook.com/tools/explorer/?method=GET例如,facebook explorer 确实会像这样列出响应 json obj 的详细信息。

{
"id": "xxx",
"name": "xxx",
"first_name": "xxx",
"last_name": "xxx",
"link": "xxx",
"username": "xxx",
"hometown": {
"id": "xxx",
"name": "xxx"
},
"location": {
"id": "xxx",
"name": "xxx"
},
"bio": "Drink Coffee in Whitehorse",

"work": [
{
"employer": {
"id": "xxx",
"name": "xxx"
},
"location": {
"id": "xxx",
"name": "xxx"
},
"position": {
"id": "xxx",
"name": "xxx"
},
"start_date": "2009-01",
"end_date": "0000-00"
},
}

最佳答案

您只需使用 indent 关键字参数调用 json.dumps(),该关键字参数等于缩进生成的 JSON 的空格数,以进行 pretty-print 。

例如:

json.dumps(spam_and_eggs, indent=4)

关于python - 使用 django 模板将 json 填充为 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9238616/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com