通过嵌套字典进行迭代,并在Django html页面中打印

问题描述 投票:0回答:1

我有这样的字典

mainDict={'RA CROXE-16353': 
 {'ENGINEER_NAME': 'Leela', 'DESCRIPTION': 'M5  Rainbow when it is conversation with external',      'BINARIES': 'SYM'},  
'RA CROXE-16344': 
{'ENGINEER_NAME': 'MARK', 'DESCRIPTION': 'M5 Network SIP ISDN TLS call with VPN_G729', 'BINARIES': 'TEL.1.so'}
     }

我想遍历字典,以便可以在Django中以表格格式打印。

CR              ENGINEER_NAME     DESCRIPTION                                        BINARIES

RA CROXE-16353  Leela             M5  Rainbow when it is conversation with external  SYM
RA CROXE-16344  MARK              M5 Network SIP ISDN TLS call with VPN_G729         TEL.1.so

请任何人,让我知道如何进行操作

<table class="table">
    <tr>
        <td>CR</td>
        <td>Engineer Name</td>
        <td>Description</td>
        <td>Binaries</td>
    </tr>
    {% for key,value in mainDict.items %}
        {% for k,val in value.items %}
    <tr>
        <td>{{key}}<td>         
        <td> {{ value }} </td>      
    </tr>
        {% endfor %}
    {% endfor %}

</table>

我试图用键和值来遍历代码,但无法以所需的格式打印。

django python-3.x dictionary nested-loops
1个回答
0
投票

我认为您需要从一个这样的结构开始:它可以是looped

CRS = [
    'RA CROXE-16353': {
          'ENGINEER_NAME': 'Leela', 
          'DESCRIPTION': 'M5  Rainbow when it is conversation with external',
          'BINARIES': 'SYM'
    },  
    'RA CROXE-16344': {
         'ENGINEER_NAME': 'MARK', 
         'DESCRIPTION': 'M5 Network SIP ISDN TLS call with VPN_G729', 
         'BINARIES': 'TEL.1.so'
    }
]
© www.soinside.com 2019 - 2024. All rights reserved.