Created
June 6, 2013 19:11
-
-
Save dayorbyte/5724082 to your computer and use it in GitHub Desktop.
Simple tornado example
This file contains 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 | |
from tornado.web import RequestHandler | |
class HomeHandler(RequestHandler): | |
def get(self): | |
self.write('Hello, world') | |
def post(self): | |
self.write('<h1>You posted to get here!</h1>') | |
self.write('Name: ' + self.get_argument('name')) | |
self.write('<h2>All Args</h2>') | |
for arg, values in self.request.arguments.iteritems(): | |
self.write('<li>') | |
self.write(arg + ':') | |
self.write(','.join(values)) | |
self.write('</li>') | |
class JsonHandler(RequestHandler): | |
def get(self): | |
self.write({'value' : 'this is written as JSON automatically'}) | |
application = tornado.web.Application([ | |
(r'/', HomeHandler), | |
(r'/api/jsonexample', JsonHandler), | |
]) | |
if __name__ == '__main__': | |
application.listen(8888) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment