[gae] 無法輸出 html 組件?

  • 3153
  • 0

[gae] 無法輸出 html 組件?

原本我的 template 是這樣寫的:

{{ option_select }}

只要我輸出 option_select = '<select name="your_select" ><option value="*" >*</option></select>' 就可以輸出一個下拉式選單。

image

這次從本地的GAE開發從 1.8.0 更新到 GAE 1.9.0 之後就失敗了,輸出不是一個下拉選單,而是文字,把我上面那串字直接輸出了。

image

原來是為了安全,會把文字的部份都做 html encode,所以就變成畫面上是文字直接輸出。

要改回原來的樣子,就是在 tempalte 內加上 safe。

{{ option_select|safe }}

就好了!

 

 

備註:如果遠端 server 使用的還是 python 而不是 python27,|safe 還是不支援…。

參考:

http://stackoverflow.com/questions/4800894/google-app-engine-template-not-working-when-displaying-html-form

 

 

 

分享