【发布时间】:2021-08-13 05:00:42
【问题描述】:
我在浏览器中有来自 HTML 模板的这个输出:
{'coin__name': 'Bitcoin', 'total': Decimal('1498824')}
{'coin__name': 'Ripple', 'total': Decimal('335227')}
如何在 html 模板中分别显示键和值(不说十进制)?
期望的结果:
Bitcoin, 1498824
Ripple , 335227
我在下面提供查询和 html 模板:
views.py:
test = filtered_transaction_query_by_user.values('coin__name').annotate( total = (Sum('trade_price' ) * Sum('number_of_coins'))).order_by('-total')
template.html
<table class="table table-striped">
<tr>
<th>Current dict pair</th>
<th>Just the name of the crypto</th>
<th>Just the price of the crypto</th>
</tr>
{% for item in test %}
<tr>
<td>{{ item }}</td>
<td>{{ }}</td>
<td>{{ }}</td>
</tr>
{% endfor %}
【问题讨论】:
-
item.0和item.1给你什么?
标签: python django django-templates django-queryset django-template-filters