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. java - new + 類名,一定需要申明一個對象嗎?2. javascript - 前端開發 本地靜態文件頻繁修改,預覽時的緩存怎么解決?3. java - public <T> T findOne(T record) 這是什么意思4. android - 優酷的安卓及蘋果app還在使用flash技術嗎?5. docker不顯示端口映射呢?6. mysql數據庫每次查詢是一條線程嗎?7. python - linux怎么在每天的凌晨2點執行一次這個log.py文件8. javascript - 我的站點貌似被別人克隆了, google 搜索特定文章,除了域名不一樣,其他的都一樣,如何解決?9. 如何分別在Windows下用Winform項模板+C#,在MacOSX下用Cocos Application項目模板+Objective-C實現一個制作游戲的空的黑窗口?10. 小程序怎么加外鏈,語句怎么寫!求救新手,開文檔沒發現
