1

我有一个这样的嵌套字典

{
"OFPAT_OUTPUT": {
    "0": "Grp100No100", 
    "1": "Grp100No120", 
    "2": "Grp100No150", 
    "3": "Grp40No50", 
    "4": "Grp40No60"
}, 
"OFPAT_SET_DL_SRC": "Grp70No170", 
"OFPAT_SET_NW_DST": {
    "0": {}
}, 
"OFPAT_SET_TP_DST": {
    "0": "Grp70No230"
}, 
"OFPAT_SET_TP_SRC": {
    "0": "Grp70No220"
}, 
"OFPAT_SET_VLAN_PCP": "Grp70No140", 
"OFPAT_SET_VLAN_VID": {
    "0": "Grp70No120", 
    "1": "Grp70No130", 
    "2": "Grp70NO250"
}, 
"OFPAT_STRIP_VLAN": {
    "0": "Grp70No160"
}, 
"OFPC_ARP_MATCH_IP": {
    "0": "Grp50No210", 
    "1": "Grp50No220"
}, 
"OFPC_FLOW_STATS": {
    "0": "Grp60No10", 
    "1": "Grp60No20", 
    "2": "Grp60No30", 
    "3": "Grp60No40"
}, 
"OFPC_PORT_STATS": {
    "0": "Grp60No60", 
    "1": "Grp60No70", 
    "10": "Grp60No160", 
    "2": "Grp60No80", 
    "3": "Grp60No90", 
    "4": "Grp60No100", 
    "5": "Grp60No110", 
    "6": "Grp60No120", 
    "7": "Grp60No130", 
    "8": "Grp60No140", 
    "9": "Grp60No150"
}, 
"OFPC_QUEUE_STATS": {
    "0": "Grp60No170", 
    "1": "Grp60No180", 
    "2": "Grp60No190"
}, 
"OFPC_TABLE_STATS": "Grp60No210"
}

我想将它打印到 html 文件 OFPAT_OUTPUT 应该出现在它具有在字典中看到的值的所有行中。应该是这样的。我需要帮助迭代字典

    <tr>
      <td>OFPAT_OUTPUT</td>
      <td>Grp100No100</td>
    </tr>
    <tr>
      <td>OFPAT_OUTPUT</td>
      <td>Grp100No120</td>
    </tr>
     <tr>
      <td>OFPAT_OUTPUT</td>
      <td>Grp100No150</td>
    </tr>
     <tr>
      <td>OFPAT_OUTPUT</td>
      <td>Grp40No150</td>
    </tr>
     <tr>
      <td>OFPAT_OUTPUT</td>
      <td>Grp40No60</td>
    </tr>

我正在使用 jinja2。我有以下代码。

{% for AT, test in matching.items()  %}
    {%- if test %}
             {% for testno,testname in matching[test] %}
        <tr>
             <td>{{AT}}</td>

            <td> {{testname}}</td>

        </tr>
      {% endfor %} 
    {%- endif %}
{% endfor %}

有什么帮助吗??

4

0 回答 0