http_client = httpclient.HTTPClient()
try:
response = http_client.fetch("http://www.google.com/")
- print response.body
+ print(response.body)
except httpclient.HTTPError as e:
# HTTPError is raised for non-200 responses; the response
# can be found in e.response.
def handle_response(response):
if response.error:
- print "Error:", response.error
+ print("Error:", response.error)
else:
- print response.body
+ print(response.body)
http_client = AsyncHTTPClient()
http_client.fetch("http://www.google.com/", handle_response)
To load a locale and generate a translated string::
user_locale = tornado.locale.get("es_LA")
- print user_locale.translate("Sign out")
+ print(user_locale.translate("Sign out"))
`tornado.locale.get()` returns the closest matching locale, not necessarily the
specific locale you requested. You can support pluralization with
people = [...]
message = user_locale.translate(
"%(list)s is online", "%(list)s are online", len(people))
- print message % {"list": user_locale.list(people)}
+ print(message % {"list": user_locale.list(people)})
The first string is chosen if ``len(people) == 1``, otherwise the second
string is chosen.
Basic usage looks like::
t = template.Template("<html>{{ myvalue }}</html>")
- print t.generate(myvalue="XXX")
+ print(t.generate(myvalue="XXX"))
`Loader` is a class that loads templates from a root directory and caches
the compiled templates::
loader = template.Loader("/home/btaylor")
- print loader.load("test.html").generate(myvalue="XXX")
+ print(loader.load("test.html").generate(myvalue="XXX"))
We compile all templates to raw Python. Error-reporting is currently... uh,
interesting. Syntax for the templates::