我有数据库,目前来 self 的数据库,它在我的模板(HTML 表格)页面中显示如下。
sno--scene--frames--empID
1------001----24-----100
2------002----34-----100
3------003----20-----101
4------004----15-----101
5------005----10-----100
但我想像这样显示(如下)。如何从 HTML
(表格)中获取。我正在使用 Python-Django。
sno---scene---frames---empID
1--------001-----24-------100
2--------002-----34-------100
3--------005-----10-------100
------------- tot=68
1------003-----20--------101
2------004-----15--------101
-------------tot=35
最佳答案
您应该在 View 中准备数据 - 按 id 对它们进行分组,计算总和。结果 cal 如下所示:
items_info = [{'items':[item1, item2, item3], 'total': 68}, {'items':[item4, item5], 'total': 35}]
那么模板应该是这样的:
{% for info in items_info %}
{% for item in info.items %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ item.scene }}</td>
<td>{{ item.frames }}</td>
<td>{{ item.id }}</td>
</tr>
{% endfor %}
<tr>
<td colspan="3">TOTAL</td>
<td>{{ info.total }}
</tr>
{% endfor %}
希望这对您有所帮助!
关于Python-Django : user info in template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13412242/