flask - python 多維字典遍歷
問題描述
python多維數(shù)組遍歷問題:
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}}
現(xiàn)在想遍歷這個(gè)字典:
<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>
但是這樣遍歷數(shù)組好像不行耶,求指點(diǎn)
問題解答
回答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
相關(guān)文章:
1. macOS Sierra 10.12 安裝mysql 5.7.1出現(xiàn)錯(cuò)誤2. mysql - 拖拽重排序后怎么插入數(shù)據(jù)庫?3. android - 安卓做前端,PHP做后臺(tái)服務(wù)器 有什么需要注意的?4. javascript - 天貓首頁首屏數(shù)據(jù)來源5. mysql 獲取時(shí)間函數(shù)unix_timestamp 問題?6. mysql - 僅僅只是把單引號(hào)與反斜杠轉(zhuǎn)義不用prepare statement能否避免sql注入?7. php - 生產(chǎn)環(huán)境下,給MySQL添加索引,修改表結(jié)構(gòu)操作,如何才能讓線上業(yè)務(wù)不受影響?8. mysql主主同步,從庫不同步應(yīng)該怎么解決?9. mysql在限制條件下篩選某列數(shù)據(jù)相同的值10. 新入手layuiadmin,部署到tp中。想用php自已寫一個(gè)后臺(tái)管理系統(tǒng)。
