gpt4 book ai didi

python - Django 。如何在html namevaluedate标签中显示json文件?

转载 作者:太空宇宙 更新时间:2023-11-04 05:56:35 27 4
gpt4 key购买 nike

我想这是个愚蠢的问题,但我是 json 的新手,所以任何答案都会有所帮助。

我有 json 文件:

`{"aaData": [
[1, "70.1700", "2008-12-29 11:23:00"],
[2, "70.2600", "2008-12-29 16:22:00"],
[3, "70.6500", "2008-12-30 11:30:00"],
[4, "70.8700", "2008-12-30 16:10:00"],
[5, "70.5500", "2009-01-02 11:09:00"],
[6, "70.6400", "2009-01-02 16:15:00"],
[7, "70.6500", "2009-01-05 11:17:00"]
]}`

我的应用程序.html:

<li><a href="{%  url  'my_app.views.specific_document'  document.id  %}">{{ document.docfile.name }}</a></li>

这是我的 View 函数:

    def specific_document(request, document_id=1):
json_file = Document.objects.get(id=document_id).docfile.url
mydata = json.loads(json_file)
return render(request, 'specific_document.html', {"mydata": mydata, "documents": documents}, content_type="application/xhtml+xml")

模板“specific_document.html”应该如何像我在主题中询问的那样显示数据?

最佳答案

为了得到表格,你应该放这样的东西:

<table>
{% for name, items in mydata.iteritems %}
<!-- name = 'aaData' and items = [ list of entries ] -->
{% for item in items %}
<!-- item is ["number", "value", "date"] and you can access them by index -->
<!-- Name -->
<tr>
<td>{{name}}</td>
<!-- Value -->
<td>{{item.1}}</td>
<!-- Date -->
<td>{{item.2}}</td>
</tr>
{% endfor %}
{% endfor %}
</table>

在这里,我首先浏览字典(for name, items in mydata.iteritems),然后浏览该字典条目列表中的每个条目。

关于python - Django 。如何在html <tr><td>name</td><td>value</td><td>date</td></tr>标签中显示json文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27450698/

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