即時得到在Django奇怪的錯誤至今:Django的「如果」語句格式不正確
'if' statement improperly formatted
模板引發錯誤是這樣的:有一個和DIFF在上下文
{% if diff >= 0 %}
<span class="pos">+{{ diff }}
{% else %}
<span class="neg">-{{ diff }}
{% endif %}
</span>
<span>{{ a }}</span>
視圖這個:
def add(request, kaart_id):
if request.is_ajax() and request.method == 'POST':
x = Kaart.objects.get(id=kaart_id)
x.pos += 1
x.save
x = Kaart.objects.get(id=kaart_id)
from django.utils import simplejson
diff = x.pos - x.neg
a = "(+1)"
context = { 'diff':diff, 'a':a }
return render_to_response('sum.html', context, context_instance=RequestContext(request))
無論我用什麼等式if,>,> =,== ..他們都會引起同樣的錯誤。
並儘可能我可以告訴所有的書:http://docs.djangoproject.com/en/dev/ref/templates/builtins/#id5
艾倫。
謝謝!我想到別的東西然後等待1.2! – 2009-12-20 20:36:15
只需使用標籤即可。它很容易加載它們(在文檔中),然後當1.2發佈時,你的代碼已經兼容,你可以刪除標籤代碼。 – 2009-12-21 02:55:46