【发布时间】:2019-08-25 15:31:37
【问题描述】:
我正在考虑使用 HTML 将格式良好的数据发布到网页上。我使用 Flask 和 Mongodb 作为我的数据库在 python 中编写了一个代码。
@app.route('/')
def Results():
try:
Project_List_Col = db.ppm_master_db_collection.find({},
{"_id":0})
return render_template('Results.html',tasks=Project_List_Col)
except Exception as e:
return dumps({'error': str(e)})
if __name__ == '__main__':
app.run(debug = True)
但是,数据以 JSON 格式打印。我希望将其格式化为表格格式。
这是我的 HTML 代码:
<html>
<body>
{% for task_id in tasks %}
<h3>{{task_id}}</h3>
{% endfor %}
</body>
</html>
目前的输出类似于:
[{u'total': 9942806, u'_id': {u'd': 1, u'sid': u'c1'}},
{u'total': 10173832, u'_id': {u'd': 1, u'sid': u'c2'}},
{u'total': 9567489, u'_id': {u'd': 1, u'sid': u'c3'}}]
但是,我需要它是这样的:
Day C1 C2 C3 C4
1 123 125 122 254
2 123 125 122 254
3 123 125 122 254
我需要有关如何获得可读性更好的 UI 输出的帮助。
【问题讨论】: