2009-01-21 163 views
0

生成的模板所以我有這樣的代碼在谷歌應用程序引擎模板:不正確渲染

<select name='voter'> 

{% for voter in allowed_voters %} 

    <option {% ifequal voter last_voter %}selected="yes" {% endifequal %} 
    value='{{voter}}'>{{voter}}</option> 

{% endfor %} 

</select> 

的頁面不選擇正確的人,而不是默認的第一個選項渲染。查看源代碼顯示,生成的html已將選定的屬性放在正確的位置,所以我無法弄清楚爲什麼這種方式不起作用。

回答

4

option's select attribute是一個布爾屬性。

請嘗試以下之一:

<option {% ifequal voter last_voter %}selected="selected" {% endifequal %} 
value='{{voter}}'>{{voter}}</option> 


<option {% ifequal voter last_voter %}selected {% endifequal %} 
value='{{voter}}'>{{voter}}</option> 
+0

感謝您的幫助,結果發現問題在別處。 – wodemoneke 2009-01-22 12:33:50

0

嘗試只是「選擇」,而不是選擇=「是」令牌

1

布爾屬性的語法是HTML和XHTML不同。顯然,你輸出HTML,並需要使用

<option ... selected ...> 

在XHTML中你可以使用

<option ... selected="selected" ...> 

這是不幸的,我們有全HTML/XHTML和MIME類型惹可怕的非標準 - 兼容的瀏覽器。你只需要知道這些東西,以確保你正在吐出在大多數瀏覽器上正確呈現的頁面。