html求和按钮,使用模板标记在html模板中求和

我想在

HTML中求和,但模板标签返回0,

View.py

def gen_Report(request):

### query returns below output

list=[{'total': 1744, 'user': u'x'}, {'total': 13, 'user': u'y'}, {'total': 126, 'user': u'z'}, {'total': 46, 'user': u'm'}, {'total': 4, 'user': u'n'}, {'total': 8, 'user': u'o'}, {'total': 3, 'user': u'p'}]

return render_to_response('user.html', locals(),

context_instance = RequestContext(request))

模板:

user.html

{% load temptags %}

S.NoroleCount

{% for fetch in list %}

{{forloop.counter}}{{fetch.user}}{{fetch.total}}

{% endfor %}

{{ list.total|running_total}}

模板标签:

from django.template import Library

register = Library()

@register.filter

def running_total(list_total):

return sum(d.get('list_sum') for d in list_total)

输出:

S.No user Count

1 x 1744

2 y 13

3 z 126

4 m 46

5 n 4

6 o 8

Sum------------------> 0 (it returns zero)

我在这里做错了什么?

你可以帮助我,如何在这里使用模板标签返回总和?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值