我使用这个字典列表在模板上渲染,我想在特定字典的末尾打破forloop,
如果
test_ranking_table = [
{
"Team":"India",
"Matches":"44",
"Rating":"121",
"points":"5313"
},
{
"Team":"South Africa",
"Matches":"39",
"Rating":"115",
"points":"4484"
},
{
"Team":"Australia",
"Matches":"40",
"Rating":"104",
"points":"4174"
},
{
"Team":"New Zealand",
"Matches":"35",
"Rating":"100",
"points":"3489"
},
{
"date-updated":"27 January 2018",
"match-type":"ICC Test Championship"
}
]
如果我为test_ranking_table执行for循环
<thead class="thead-inverse">
<tr>
<th class="bg-dark text-lg-left">TEAM</th>
<th class="bg-dark text-lg-left">Matches</th>
<th class="bg-dark text-lg-left">Points</th>
<th class="bg-dark text-lg-left">Rating</th>
</tr>
</thead>
<tbody>
{% for team in test_ranking_table %}
<tr class="table table-bordered">
<td>{{ team["Team"]}}</td>
<td>{{ team['Matches'] }}</td>
<td>{{ team['points'] }}</td>
<td>{{ team['Rating'] }}</td>
</tr>
{% endfor %}
由于最后一组字典{'date-updated': '27 January 2018', 'match-type': 'ICC Test Championship'}
的键和值不同,我最后得到一个空行表
那么我怎么能在它转到最后一组字典之前打破循环,所以我不会得到任何空表行。