2011-11-04 36 views
0

我想比較兩個數字,但我得到了以下錯誤:遇到問題做簡單的數字比較和Django

Could not parse the remainder: '{{hole.number}}' from '{{hole.number}}' 

這裏是我的代碼:

{% if (hole.number - 1) > 0 %} 
    ... 
    {% endif %} 

hole.number是正整數,所以比較應該是有效的。

+1

那裏的頂部是關於哲學的一個非常大的音符,你最好這樣做在你的觀點[模板文檔](https://docs.djangoproject.com/en/1.3/topics/templates/),這清楚地解釋了爲什麼這樣的事情不起作用。 –

+0

{%如果hole.number> 1%}? :P – niklasdstrom

回答

0

這可能會實現,但說實話如果可以的話,否則就是以模板標籤

{% with hole.number|add:"-1" as num %} 
{% if num > 0 %} 
... 
{% endif %} 
{% endwith %}