【发布时间】:2018-10-22 09:00:40
【问题描述】:
我需要在我的模板中打印一个表格,其中包含已在我的视图中处理的数据。它在 collections.OrderedDict() 变量中:
table_dict[position] = {'date': item['date'],
'document': item['document'],
'details': item['details'],
'quantity_balance': quantity_balance,
'unit_price_balance': unit_price_balance,
'total_price_balance': total_price_balance,
'quantity_buy': 0,
'unit_price_buy': 0,
'total_price_buy': 0,
'quantity_sell': 0,
'unit_price_sell_avrg': 0,
'total_price_sell_avrg': 0,
'unit_price_sell': 0,
'total_price_sell': 0,
'earn_total_sell': 0}
我的职位不止一个,下面是Python的控制台打印示例:
{'total_price_sell_avrg': 0, 'quantity_balance': Decimal('1.000000000000000000'), 'date': datetime.date(2018, 5, 10), 'document': '9d4f8661', 'unit_price_sell_avrg': 0, 'total_price_sell': 0, 'total_price_balan
e': Decimal('2400000.000000000000000000000'), 'quantity_sell': 0, 'unit_price_buy': 0, 'details': 'Initial Investment', 'quantity_buy': 0, 'earn_total_sell': 0, 'unit_price_balance': Decimal('2400000.0000000000
0000000'), 'total_price_buy': 0, 'unit_price_sell': 0}
{'total_price_sell_avrg': 0, 'quantity_balance': Decimal('1.500000000000000000'), 'date': datetime.date(2018, 5, 10), 'document': '09asdashd', 'unit_price_sell_avrg': 0, 'total_price_sell': 0, 'total_price_bala
ce': Decimal('3750000.000000000000000000000'), 'quantity_sell': 0, 'unit_price_buy': Decimal('2700000.000000000000000000'), 'details': '08a7sd80a7doiadsiaud0a87ds', 'quantity_buy': Decimal('0.500000000000000000
), 'earn_total_sell': 0, 'unit_price_balance': Decimal('2500000.000'), 'total_price_buy': Decimal('1350000.000000000000000000000'), 'unit_price_sell': 0}
现在我有一个有序表,我想在我的 html 模板中打印它,它基本上具有这样的结构:
<table class="tablerow">
<tr>
<th colspan="4"></th>
<th colspan="3">Buys</th >
<th colspan="3">Sells</th>
<th colspan="3">Total</th>
</tr>
<tr>
<th >Num T</th>
<th >Date</th>
<th >Document number</th>
<th >Type Operation</th>
<th >Details</th>
<th >Quantity</th>
<th >Unit Price</th>
<th >Total Price</th>
<th >Quantity</th>
<th >Unit Price</th>
<th >Total Price</th>
<th >Quantity</th>
<th >Unit Price</th>
<th >Total Price</th>
</tr>
</table>
如何在我的 html 上打印我的字典来维护订单? 我将字典作为上下文传递给模板:
context = {'table':table}
非常感谢您的帮助!祝你今天过得愉快。 PD:我也尝试使用自定义过滤器标签,但我无法构建一个适用于这种情况的标签,也许我不明白它们如何适用于这种情况。
【问题讨论】:
标签: python django dictionary django-templates