龙卷风web应用程序中的Unicode字符串

时间:2011-04-13 10:24:10

标签: python tornado

如何在龙卷风视图或模板中使用unicode字符串?
我插入模板
<meta http-equiv="content-type" content="text/html;charset=utf-8" /> 在视图中

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

1 个答案:

答案 0 :(得分:1)

准备好unicode字符串后,请求应该结束

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

这会呈现文件&#34; template.html&#34;将aString变量设置为aUnicodeString。

template.html看起来像这样:

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

也可以在Tornado服务器中内联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