问题描述
如何在 Tornado 视图或模板中使用 unicode 字符串?
我插入模板<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
并且在查看
How can I use unicode strings in tornado views or templates?
I insert in template<meta http-equiv="content-type" content="text/html;charset=utf-8" />
And in view
# -- coding: utf-8 --
输出是????
推荐答案
准备好 unicode 字符串后,请求应该结束
Once you have your unicode string ready, the request should end
self.render("template.html", aString=aUnicodeString)
这会渲染文件template.html",将 aString 变量设置为 aUnicodeString.
This renders the file "template.html" setting the aString variable to aUnicodeString.
template.html 看起来像这样:
template.html would look something like this:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
{{aString}}
</body>
</html>
也可以在 Tornado 服务器中内联 HTML.
It's also possible to inline the HTML in the Tornado server.
self.render('<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>{{aString}}</body></html>', aString=aUnicodeString)
这里有更多关于模板的信息:
More on templates here:
这篇关于Tornado Web 应用程序中的 Unicode 字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!