【问题标题】:Django render in html AggregationDjango 在 html 聚合中渲染
【发布时间】:2019-07-12 06:22:01
【问题描述】:

我正在尝试通过 django 在 html 中输出条件总和/聚合。虽然不确定在我的模板中放什么?

见下文:

在views.py中:(我的部分代码)

total_paid = CF.objects.filter(type='Payment').aggregate(Sum('amount')
return render(request, 'budget/budget_detail.html', {'paid': total_paid })

在预算/budget.html 中:

{{ paid }} 

在我的浏览器中输出如下:{'amount__sum': Decimal('-1500')}

谁能帮助我?谢谢!!

【问题讨论】:

    标签: django filter render aggregation templatetags


    【解决方案1】:

    你正在寻找

     {{ paid.amount__sum }}
    

    虽然您可能只想为聚合中的总和提供一个键,以使其成为更好的变量名称

    ...aggregate(total=Sum('amount'))
    {{ paid.total }}
    

    【讨论】:

      猜你喜欢
      • 2020-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-12
      • 2021-02-17
      • 2018-12-13
      • 1970-01-01
      • 2010-11-25
      相关资源
      最近更新 更多