每 table 行烧瓶 4 件物品
Flask 4 items per table row
我正在使用一组对象在 FLASK 中制作一个 table。我想每 table 行显示 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>
对于此事的任何帮助,我将不胜感激。
batch
returns 一个容器,里面有 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 %}
我正在使用一组对象在 FLASK 中制作一个 table。我想每 table 行显示 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>
对于此事的任何帮助,我将不胜感激。
batch
returns 一个容器,里面有 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 %}