【发布时间】:2020-07-02 05:02:54
【问题描述】:
我想从这个传递的 JSON 中将 Alice 打印为从视图到 HTML 文件的字典。
这是我的视图文件
result = json.loads(JSON_DATA.content)
return render(request, 'home.html', {'result' : result})
{
"firstName" : "Jane",
"lastName" : "Dow",
"hobbiles" : ["running", "sky diving", "singing"],
"age" : 35,
"children" : [
{
"firstName" : "Alice",
"age" : 6,
},
{
"firstName" : "Bob",
"age" : 8,
}
]
}
这是我在 HTML 模板中尝试过的
{{ result.children[0].firstName }}
这会引发错误 * TemplateSyntaxError* 无法从“result.children[0].firstName”解析余数“[0].firstName”
如何访问 HTML 模板中的值?
【问题讨论】:
标签: django python-3.x django-views django-templates