django:模板如何连续填满3个项目的表格 [英] django: templates how to fill a table of 3 items in a row

查看:92
本文介绍了django:模板如何连续填满3个项目的表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用结果列表填充表格。但是不确定在当前交易中已经显示了3种产品之后,该如何告诉模板关闭电流并启动一个新产品的时间。...

I want to fill a table with a list of results. But not sure how to tell the template that it's time to close current and start a new one, after 3 products was already displayed in current tr....

很高兴有人可以提出建议。我正在运行django 1.1.1

Would be happy if somebody could advice on it. I am running django 1.1.1

推荐答案

最简单的方法是使用 divisibleby 过滤器。

Easiest way is to use the divisibleby filter.

{% for item in results %}
{% if forloop.counter0|divisibleby:3 %}<tr>{% endif %}
<td>{{ item }}</td>
{% if forloop.counter|divisibleby:3 %}</tr>{% endif %}
{% endfor %}

这篇关于django:模板如何连续填满3个项目的表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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