在我看来,我正在创建一个名为records_list的列表。在该列表中,我在位置[0]处有另一个列表,在位置[1]处有一个字典,如下所示:
records_list = list()
list_one = Bet.objects.order_by('-game_date')
list_two = {}
在“ list_two”(即我的字典)中,我有一个键,其日期为“ April 2016”,例如,还有一个值为元组的值:
list_two[aux_month_year] = (aux_wins, aux_losses, aux_voids, s_rate, i_rate, profit)
所以我将其返回到我的html中:
records_list.append(list_one)
records_list.append(list_two)
return records_list
在html中,我想创建一个表,然后首先检查我的利润是否为正:
{% if records_list %}
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Wins</th>
<th>Losses</th>
<th>Void</th>
<th>Success Rate</th>
<th>Return on Investment</th>
<th>Profit</th>
</tr>
</thead>
{% for key in records_list.1 %}
{% if records_list.1.key.5 > 0 %}
<tr class="success">
<td>{{ key }}</td>
<td>{{ records_list.1.key.0 }}</td>
<td>{{ records_list.1.key.1 }}</td>
<td>{{ records_list.1.key.2 }}</td>
<td>{{ records_list.1.key.3 }}%</td>
<td>{{ records_list.1.key.4 }}%</td>
<td>{{ records_list.1.key.5 }}</td>
</tr>
但是,当我尝试访问时,records_list.1.key.5
我什么也没得到...这就是我得到的<span>Here: {{ records_list.1}}</span>
:
Here: {u'April 2016': (1, 1, 0, 0.0, 125.0, 5.0), 'Total': (1, 1, 0, 0.0, 125.0, 5.0)}Here: {u'April 2016': (1, 1, 0, 0.0, 125.0, 5.0), 'Total': (1, 1, 0, 0.0, 125.0, 5.0)}
如果发生以下情况,会发生以下情况<span>Here: {{ records_list.1.key.5}}</span>
:
Here: Here:
但是,当我访问时,{{ key }}
我得到的是:“ 2016年4月”和“总计” ...
我使用以下方法解决了我的问题:
{% for key, value in records_list.1.items %}
然后:
{% for key, value in records_list.1.items %}
{% if value.5 > 0 %}
<tr class="success">
<td>{{ key }}</td>
<td>{{ value.0 }}</td>
<td>{{ value.1 }}</td>
<td>{{ value.2 }}</td>
<td>{{ value.3 }}%</td>
<td>{{ value.4 }}%</td>
<td>{{ value.5 }}</td>
</tr>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句