【发布时间】:2015-03-16 08:13:34
【问题描述】:
我在 django 应用程序中有一个包含对象的页面。我使用 for 循环显示它。如果循环处于 5 个周期,我想做类似的事情,我想出现在新页面上。我需要这个来生成pdf文件。 在每个站点上,我只想拥有 5 个对象。但是下面的这个解决方案对我不起作用。
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<h3>{% trans 'In progress' %}</h3>
{% for worked_on in worker.worked_on.all %}
<tr>
<td width="33%" align="left" valign="top"> </td>
<td width="67%" class="project-name">
<a href="#">{{ translated_project.title }}</a>
</td>
</tr>
<tr>
<td class="project-image" width="33%" align="left" valign="top">
// CONTENT
</td>
<td class="project-description" valign="top">
// CONTENT
</td>
</tr>
<tr>
<td>
<p>
{% if forloop.counter == 5 %}
<div style="page-break-after: always;"></div>
{% endif %}
</p>
</td>
</tr>
{% endfor %}
</table>
【问题讨论】:
标签: python django templates for-loop