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. 運(yùn)行python程序時(shí)出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯(cuò)誤?2. 在mac下出現(xiàn)了兩個(gè)docker環(huán)境3. 利用IPMI遠(yuǎn)程安裝centos報(bào)錯(cuò)!4. spring-mvc - spring-session-redis HttpSessionListener失效5. javascript - QQ第三方登錄的問題6. 測(cè)試自動(dòng)化html元素選擇器元素ID或DataAttribute [關(guān)閉]7. javascript - node得到req不能得到boolean8. javascript - 最近用echarts做統(tǒng)計(jì)圖時(shí)遇到兩個(gè)問題!!9. java - Spring boot 讀取 放在 jar 包外的,log4j 配置文件,系統(tǒng)有創(chuàng)建日志文件,不寫入日志信息。10. javascript - 在 model里定義的 引用表模型時(shí),model為undefined。

網(wǎng)公網(wǎng)安備