This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print "Blocking HTTPClient" | |
from tornado import ioloop | |
from tornado import httpclient | |
http_client = httpclient.HTTPClient() | |
try: | |
http_client.fetch("http://google.co.in/") | |
print "HTTPClient Response" | |
except httpclient.HTTPError, e: | |
print "Error:", e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print "\nNon-Blocking AsyncHTTPClient" | |
import tornado.ioloop | |
def async_call(response): | |
if response.error: | |
response.rethrow() | |
print "AsyncHTTPClient Response" | |
ioloop.IOLoop.instance().stop() | |
http_client = httpclient.AsyncHTTPClient() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello World! | Hallo Welt! | |
---|---|---|
Thank You | Danke |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.locale | |
import tornado.web | |
import os | |
class ENHandler(tornado.web.RequestHandler): | |
def get(self): | |
tornado.locale.set_default_locale('us_US') | |
self.render("locale_template.html") | |
class FRHandler(tornado.web.RequestHandler): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
import tornado.database | |
class Main(tornado.web.RequestHandler): | |
def get(self): | |
self.write("Main") | |
class DBHandler(tornado.web.RequestHandler): | |
def get(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<title> | |
SQLite Example | |
</title> | |
<body> | |
<FORM ACTION="/create" METHOD=POST> | |
Name: <input type="text" name="name"> | |
Marks: <input type="text" name="marks"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<title> | |
JSON Example | |
</title> | |
<body> | |
<FORM ACTION="/blog" METHOD=POST> | |
Title: <input type="text" name="title"> | |
Author: <input type="text" name="author"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.httpclient | |
http = tornado.httpclient.HTTPClient() | |
response = http.fetch("http://localhost:8888/lang") | |
data = tornado.escape.json_decode(response.body) | |
print data['py'], data['js'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.web | |
import tornado.escape | |
class Main(tornado.web.RequestHandler): | |
def get(self): | |
self.write("<br />") | |
self.write(tornado.escape.linkify("Linked URL: http://technobeans.com/2012/08/22/tornado-database-mysql-client-wrapper/")) | |
self.write("<br />") | |
self.write(tornado.escape.linkify("Short URL: http://technobeans.com/2012/08/22/tornado-database-mysql-client-wrapper/", shorten=True)) | |
self.write("<br />") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tornado.options import define, options | |
import tornado.web | |
import tornado.database | |
define("host", default="localhost", help="DB host") | |
define("database", default="mydb", help="DB used") | |
define("user", default="root", help="DB username") | |
define("password", default="root", help="DB Password") | |
define("port", default=8888) |