Unicode strings in tornado web app

前端 未结 1 1675
夕颜
夕颜 2021-01-23 16:34

How can I use unicode strings in tornado views or templates?
I insert in template

相关标签:
1条回答
  • 2021-01-23 17:23

    Once you have your unicode string ready, the request should end

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

    This renders the file "template.html" setting the aString variable to aUnicodeString.

    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>
    

    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 Server Documentation

    0 讨论(0)
提交回复
热议问题