Python tornado web应用程序中的Unicode字符串
如何在tornado视图或模板中使用unicode字符串?Python tornado web应用程序中的Unicode字符串,python,tornado,Python,Tornado,如何在tornado视图或模板中使用unicode字符串? 我在模板中插入 和视图中的代码:utf-8-- # -- coding: utf-8 -- 输出是???一旦您准备好unicode字符串,请求应该结束 self.render("template.html", aString=aUnicodeString) 这将呈现文件“template.html”,将aString变量设置为aUnicodeString template.html的外观如下所示: <html>
我在模板中插入
和视图中的代码:utf-8--
# -- coding: utf-8 --
输出是???一旦您准备好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>
{{aString}}
也可以在Tornado服务器中内联HTML
self.render('<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>{{aString}}</body></html>', aString=aUnicodeString)
self.render('{{aString}}',aString=aUnicodeString)
有关模板的更多信息,请参见:
一旦您准备好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>
{{aString}}
也可以在Tornado服务器中内联HTML
self.render('<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>{{aString}}</body></html>', aString=aUnicodeString)
self.render('{{aString}}',aString=aUnicodeString)
有关模板的更多信息,请参见:
尝试:打印u“unicode字符串”。编码(“utf-8”)
尝试:打印u“unicode字符串”。编码(“utf-8”)