【发布时间】:2017-10-25 18:35:04
【问题描述】:
我想遍历对象列表并计算有多少对象满足要求。我的代码基于我找到的其他示例,但它不起作用,循环后计数始终为 0。
对于每个房子,我想遍历每个房间并计算有多少房间有一张床。我想输出,然后重置下一个房子的计数。
{% for house in city %}
{% set count = 0 %}
<div>{{ house.address }} has {{ count }} beds in it rooms.</div>
{% for room in house %}
{% if room.has_bed == True %}{% set count = count + 1 %}{% endif %}
{% endfor %}
{% endfor %}
【问题讨论】: