Skip to content

Instantly share code, notes, and snippets.

@dayorbyte
Created June 6, 2013 19:11
Show Gist options
  • Save dayorbyte/5724082 to your computer and use it in GitHub Desktop.
Save dayorbyte/5724082 to your computer and use it in GitHub Desktop.
Simple tornado example
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