2011-04-13 33 views
1

如何在龍捲風視圖或模板中使用unicode字符串?
我插入模板
<meta http-equiv="content-type" content="text/html;charset=utf-8" /> 並鑑於
龍捲風web應用中的Unicode字符串

# -- coding: utf-8 --
輸出是????

+0

嘗試:'打印U 「Unicode字符串」 .encode( 「UTF-8」)' – vartec 2011-04-13 10:28:35

+0

和模板? – Stan 2011-04-13 10:46:36

回答

1

一旦你有你的unicode字符串準備,請求應該結束

self.render("template.html", aString=aUnicodeString) 

這使得文件「template.html」設置ASTRING變量aUnicodeString。

template.html會是這個樣子:

<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
    </head> 
    <body> 
     {{aString}} 
    </body> 
</html> 

它也可以內聯在龍捲風服務器的HTML。

self.render('<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>{{aString}}</body></html>', aString=aUnicodeString) 

更多關於模板的位置:

Tornado Web Server Documentation