flask - python 多维字典遍历
问题描述
python多维数组遍历问题:
net_interfaces:{’lo0’: {’name’: ’lo0’, ’ip’: ’fe80::1%lo0’, ’bytes_sent’: 79486408, ’bytes_recv’: 79486408, ’packets_sent’: 59982, ’packets_recv’: 59982, ’errors_in’: 0, ’errors_out’: 0, ’dropped_in’: 0, ’dropped_out’: 0}}
现在想遍历这个字典:
<table class='table'> <thead> <tr> <th>Interface</th> <th>IP</th> <th>RX/s</th> <th>TX/s</th> </tr> </thead> <tbody> {% for ni in net_interfaces %} <tr> <td>{{ ni }}</td> <td>{{ ni.ip }}</td> <td>{{ ni.send_rate|default(0)|filesizeformat }}</td> <td>{{ ni.recv_rate|default(0)|filesizeformat }}</td> </tr> {% endfor %} </tbody></table>
但是这样遍历数组好像不行耶,求指点
问题解答
回答1:{% for ni in net_interfaces.lo0 %}
回答2:for key,value in data
回答3:for i in data: print i,data[i],data[i].j回答4:
for key, value in data.items
相关文章:
1. dockerfile - [docker build image失败- npm install]2. 关docker hub上有些镜像的tag被标记““This image has vulnerabilities””3. docker gitlab 如何git clone?4. docker网络端口映射,没有方便点的操作方法么?5. docker-compose中volumes的问题6. boot2docker无法启动7. mysql - phpmyadmin怎么分段导出数据啊?8. docker api 开发的端口怎么获取?9. docker不显示端口映射呢?10. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?
![dockerfile - [docker build image失败- npm install]](http://www.haobala.com/attached/image/news/202311/1028105a80.png)
网公网安备