我用一组物体用烧瓶做一张桌子。我希望每一行显示4个对象,但是batch(4)命令似乎不能正常工作。它运行,没有错误。但也没有显示任何东西。
<table class="Fruits_n_Veggies">
{% for item in fruit | batch(4) %}
{% if item.name %}
<tr>
<td class = "img"> <img src="{{ url_for('static', filename=item.img_url) }}" height="100"; width="100"><br>
{{ item.name }} {{ item.price_min }} - {{ item.price_max }}</td>
</tr>
{% endif %}
{% endfor %}
</table>我希望能在这件事上提供任何帮助。
发布于 2015-10-13 13:06:28
batch返回一个容器,其中包含4个对象。您也需要对它们进行迭代。
{% for row in fruit | batch(4) %}
<tr>
{% for item in row %}
<td class = "img"> <img src="{{ url_for('static', filename=item.img_url) }}" height="100"; width="100"><br>
{{ item.name }} {{ item.price_min }} - {{ item.price_max }}</td>
{% endfor %}
</tr>
{% endfor %}https://stackoverflow.com/questions/33101897
复制相似问题