首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >每张桌子排4件烧瓶

每张桌子排4件烧瓶
EN

Stack Overflow用户
提问于 2015-10-13 11:47:19
回答 1查看 230关注 0票数 1

我用一组物体用烧瓶做一张桌子。我希望每一行显示4个对象,但是batch(4)命令似乎不能正常工作。它运行,没有错误。但也没有显示任何东西。

代码语言:javascript
复制
 <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>

我希望能在这件事上提供任何帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-13 13:06:28

batch返回一个容器,其中包含4个对象。您也需要对它们进行迭代。

代码语言:javascript
复制
{% 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 %}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33101897

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档