【发布时间】:2018-08-07 21:40:46
【问题描述】:
因为我在 python 中有一本字典。字典值的样子。
d= {'Report.thpl Team =FULL':{'cdp.c': 899, '_arp_fusen.c': 34, 'discovery.c': 34, 'subnet.c': 4},
'P1.thpl Team = Over': {'discovery.c': 34, 'file23.c': 4, 'cdp/cdp.c': 937, '_fusen.c': 83},
'P1_Report1.thpl': {'arp_fusen.c': 83, 'disynet.c': 34, 'routes.c': 2, 'routing.c': 937}}
我的桌子是这样的
|test | file_name |coverage |
**********************************************************
|Report.thpl Team =FULL | cdp.c | 899 |
|Report.thpl Team =FULL | _arp_fusen.c | 34 |
|Report.thpl Team =FULL | Discovery.c | 34 |
|Report.thpl Team =FULL | subnet.c | 4 |
|P1.thpl Team = Over | discovery.c | 34 |
|P1.thpl Team = Over | file23.c | 4 |
|P1.thpl Team = Over | cdp/cdp.c | 937 |
|P1.thpl Team = Over | _fusen.c | 83 |
|P1_Report1.thpl | arp_fusen.c | 83 |
|P1_Report1.thpl | disynet.c | 34 |
|P1_Report1.thpl | routes.c | 2 |
|P1_Report1.thpl | routing.c | 937 |
***********************************************************
article.html 中的代码
<table class="table table-hover" style="width:80%;" >
<tr style="color:white;">
<th>Test Case</th>
<th>File Name</th>
<th>Coverage</th>
</tr>
{% for key, value in d.items %}
<tr>
{% for k,v in value.items %}
{% if forloop.parentloop.first %}
<td rowspan="{{ key|length }}">{{ key }}</td>
{% endif %}
<td>{{ k }}</td>
<td>{{ v }}</td>
{% endfor %}
</tr>
{% endfor %}
{% endif %}
</table>
但我正在使用上面的代码获得逐行输出。因为我需要以下格式的输出。请帮帮我。
|test | file_name |coverage |
**********************************************************
|Report.thpl Team =FULL | cdp.c | 899 |
| | _arp_fusen.c | 34 |
| | Discovery.c | 34 |
| | subnet.c | 4 |
|P1.thpl Team = Over | discovery.c | 34 |
| | file23.c | 4 |
| | cdp/cdp.c | 937 |
| | _fusen.c | 83 |
|P1_Report1.thpl | arp_fusen.c | 83 |
| | disynet.c | 34 |
| | routes.c | 2 |
| | routing.c | 937 |
***********************************************************
因为我需要测试属性不要重复,它应该是不同的。请帮帮我。
【问题讨论】:
-
d 不是有效的 python dict..
-
我刚刚将字典变量命名为 d
-
'Report.thpl Team =FULL'后面不应该有冒号吗? -
抱歉,我在编辑时删除了冒号。这是一本有效的字典,请根据我的需要给出显示解决方案
标签: django python-2.7 django-templates django-views