{% for frequency in patient_meds.frequency %}
{% if frequency == "7" %}
<td>Hellow</td>
{% endif %}
{% endfor%}
得到錯誤TemplateSyntaxError:「如果」語句格式不正確
TemplateSyntaxError:「如果」格式不正確的
聲明,我不知道我必須做的,請幫我...
{% for frequency in patient_meds.frequency %}
{% if frequency == "7" %}
<td>Hellow</td>
{% endif %}
{% endfor%}
得到錯誤TemplateSyntaxError:「如果」語句格式不正確
TemplateSyntaxError:「如果」格式不正確的
聲明,我不知道我必須做的,請幫我...
如果你使用Django的默認版本附帶的應用程序引擎(v0.96),那就試試這個語法:
{% for frequency in patient_meds.frequency %}
{% ifequal frequency "7" %}
<td>Hellow</td>
{% endif %}
{% endfor%}
也發生在我身上,請注意它實際上應該是{%endifequal%}。 – yonix 2011-09-23 17:45:54
的==
語法在{% if %}
標籤僅僅是因爲Django的1.2版本:)
爲了能夠使用==
語法在{% if %}
語句,你需要使用Django 1.2或以上可用。
Django 1.2附帶您的GAE SDK,但默認加載0.96。
您可以使用django的1.2版本,聲明您想使用的third-party library的版本以及由google.appengine.dist
軟件包提供的use_library()
函數。至少前從Django中導入任何東西只是把這個代碼在你的Python文件(的最頂端。
from google.appengine.dist import use_library
use_library('django', '1.2')
這樣,你的模板應很好地渲染
的語法應該是endifequal
:
{% for frequency in patient_meds.frequency %}
{% ifequal frequency "7" %}
<td>Hellow</td>
{% endifequal %}
{% endfor%}
您使用哪個django版本? – programmersbook 2011-02-04 14:21:35