Skip to content Skip to sidebar Skip to footer

Unicode Strings In Tornado Web App

How can I use unicode strings in tornado views or templates? I insert in template And in view# -- coding:

Solution 1:

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><metahttp-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><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8" /></head><body>{{aString}}</body></html>', aString=aUnicodeString)

More on templates here:

Tornado Web Server Documentation

Post a Comment for "Unicode Strings In Tornado Web App"