我这里有一个字典
dict = {1: [1,2,3,4,5,6,7,8,9],
2: [2,4,5,6,7,8,9,0],
3: [5,2,4,6,12,3,7,6]}
我想表明它在我的网页上 ,所以我使用的模板如下:
{%for item in dict.items%}
<tr>
<td>{{item.0}}</td>
{%for v in item.1%}
here ,i dont know how to handle
if last column and v >5
<td color = 'red'>{{v}}</td>
else
<td>{{v}}</td>
{%endfor%}
</tr>
{%endfor%}
如你所见,如果它的值大于5,我想让最后一列变成红色文字
我怎么能意识到这一点,我谷歌,什么都没发现
感谢所有兄弟。
当我照丹尼尔告诉:
{%for item in dict.items%}
<tr>
<td>{{item.0}}</td>
{%for v in item.1%}
{%if forloop.last and v > 5%}
<td color = 'red'>{{v}}</td>
{%else%}
<td >{{v}}</td>
{%endif%}
else
<td>{{v}}</td>
{%endfor%}
</tr>
{%endfor%}
它告诉我的错误:
Could not parse the remainder: '>5' from '>5'
Request Method: GET
Request URL: http://10.64.41.134:8000/monthlyinfo/
Django Version: 1.3
Exception Type: TemplateSyntaxError
Exception Value:
Could not parse the remainder: '>5' from '>5'
是什么问题? 再次感谢 crafet
新手说谢谢U,编辑代码,这里丹尼尔 – crafet