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
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
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
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
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
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
import tornado.ioloop | |
import tornado.web | |
import httplib2 | |
httplib2.debuglevel=1 | |
http = httplib2.Http() | |
class AsyncHandler(tornado.web.RequestHandler): | |
@tornado.web.asynchronous | |
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
import tornado.ioloop | |
import tornado.web | |
import tornado.websocket | |
class Socket(tornado.websocket.WebSocketHandler): | |
def open(self): | |
print "Socket opened" | |
def on_message(self, message): | |
self.write_message("Msg is " + message) |
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 | |
class Main(tornado.web.RequestHandler): | |
def get_current_user(self): | |
return self.get_secure_cookie("user") | |
@tornado.web.authenticated | |
def get(self): | |
## This work is achieved by decorator @tornado.web.authenticated |
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 | |
class Main(tornado.web.RequestHandler): | |
def get_current_user(self): | |
return self.get_secure_cookie("user") | |
def get(self): | |
if not self.current_user: | |
self.redirect("/login") |