我這裏有一個字典
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