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. mysql - 新浪微博中的關注功能是如何設計表結構的?2. angular.js - 關于$apply()3. MySQL數據庫中文亂碼的原因4. dockerfile - [docker build image失敗- npm install]5. angular.js使用$resource服務把數據存入mongodb的問題。6. 如何解決Centos下Docker服務啟動無響應,且輸入docker命令無響應?7. nignx - docker內nginx 80端口被占用8. angular.js - Ionic 集成crosswalk后生成的apk在android4.4.2上安裝失?。???9. android-studio - Android Studio 運行項目的時候一堆警告,跑步起來???10. 我在centos容器里安裝docker,也就是在容器里安裝容器,報錯了?
