I am trying to sum in HTML,but template tag return 0 ,
View.py
def gen_Report(request):
### query returns below output
list=[{\'total\': 1744, \'us
I suspect that your list is an iterator. So the first time it iterates over and the second time it iterate over nothing. So you should do something like this
for d in list_total:
d.set('list_sum', list(d.get('list_sum')))
before calling your template
Your template tag looks wrong. You have role_total as the parameter and then iterate through list_total (seemingly undefined) and from each dictionary in the list try getting the key list_sum which is also seemingly undefined.
from django.template import Library
register = Library()
@register.filter
def running_total(your_dict_list):
return sum(d['total'] for d in your_dict_list)
and calling it from the template at as <td>{{ list|running_total}}</td>