Python-Django : user info in template

标签 python django templates

我有数据库,目前来 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/

相关文章:

django 中文形式错误(或除英文以外的任何语言?)

python - 获取不带 "NaN"的列数

jquery - 使用 AJAX 的 Django CreateView

python - 编辑后的操纵杆代码未接收输入

python - Django级联删除反向外键

templates - 是否可以在 Julia 中声明对任何结构的一般引用?

c++ - 如何专门化容器和枚举的模板

c++ - 友元函数声明中的尖括号是什么意思?

python - 检查哥德巴赫猜想是否成立 N

python - 如何提取数据帧列中所有数字的前 2 位数字?