Django在html聚合中渲染 [英] Django render in html Aggregation

查看:46
本文介绍了Django在html聚合中渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to output a conditional sum / aggregation via django in html. Though not sure what to put in my template?

请参见下文:

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

in views.py: (part of my code )

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

in budget/budget.html中:

in budget/budget.html :

{{ paid }} 

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

output is as follows in my browser : {'amount__sum': Decimal('-1500')}

有人可以帮助我吗?谢谢!!

can anyone help me? thanks !!

推荐答案

您正在寻找

 {{ paid.amount__sum }}

尽管您可能只想为汇总中的总和提供一个键,以使其成为更好的变量名

Although you may just want to provide a key for the sum in your aggregation to make it a nicer variable name

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

这篇关于Django在html聚合中渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆