python每第3次迭代添加一个新的div [英] python add a new div every 3rd iteration

查看:67
本文介绍了python每第3次迭代添加一个新的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个产品列表,该产品列表将3个产品排成一行并清除该行,然后添加另外3个,这在IE6以外的所有地方都可以正常工作,我知道添加< div> 每组3种产品将解决此问题,目前是模板文件

I have a product list that put 3 products on a row and clears the row and adds another 3, this works fine everywhere but IE6, i know that adding <div> around each group of 3 products will solve this is the template file at the moment

{% for product in category.products.all %}
        <div class="{% cycle 'clear' '' '' %}">
            <a href="{% url shop.views.product category.slug product.slug %}"><img src="{{MEDIA_URL}}{{product.mini_thumbnail}}" alt="{{product.name}}" class="thumbnail"/></a>
            <div class="prod-details">
            <h3><a href="{% url shop.views.product category.slug product.slug %}">{{product.get_product_name}}</a></h3>
            <h4 class="strap">{{product.get_product_detail}}</h4>
            <p>{{ product.strap }}</p>
            <ul>
                <li class="price">&pound;{{product.price}}</li>
                <li class="quantity">
                    <select name="quantity_{{product.id}}">
                        <option label="1" value="1">1</option>
                        <option label="2" value="2">2</option>
                        <option label="3" value="3">3</option>
                        <option label="4" value="4">4</option>
                        <option label="5" value="5">5</option>
                        <option label="6" value="6">6</option>
                        <option label="7" value="7">7</option>
                        <option label="8" value="8">8</option>
                        <option label="9" value="9">9</option>
                    </select>
                </li>
                <li><a href="{% url shop.views.product category.slug product.slug %}">Details &gt;</a></li>
                <li class="right"><input type="submit" name="add_to_basket_{{product.id}}" value="Add to Basket &gt;"/></li>
            </ul>
            </div>
        </div>
    {% endfor %}


推荐答案

codeape的解决方案仅当您使用的是Django主干的最近SVN签出时才有效。如果您使用的是1.1版或更低版本,则不支持该语法。

codeape's solution only works if you are using a very recent SVN checkout of Django trunk. If you're using version 1.1 or below, that syntax is not supported.

相反,您可以使用 divisibleby 过滤器:

Instead, you can use the divisibleby filter:

{% if forloop.counter|divisibleby:3 %}<div>{% endif %}

这篇关于python每第3次迭代添加一个新的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆