【问题标题】:Unicode strings in tornado web app龙卷风网络应用程序中的 Unicode 字符串
【发布时间】:2011-04-13 10:24:10
【问题描述】:

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

# -- 编码:utf-8 --
输出是???

【问题讨论】:

  • 试试:print u"unicode string".encode("utf-8")

标签: python tornado


【解决方案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>

也可以在 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多