Skip to content

Instantly share code, notes, and snippets.

@ramitmittal ramitmittal/app.py
Last active Jun 29, 2019

Embed
What would you like to do?
Tornado article series 1-1
import os
import tornado
from heroes.handlers import *
class Application(tornado.web.Application):
def __init__(self):
handlers = [
("/", HomeHandler),
]
settings = dict(
debug=False,
default_handler_class=ErrorHandler,
)
super(Application, self).__init__(handlers, **settings)
def main():
tornado.log.enable_pretty_logging()
PORT = os.environ.get('PORT')
http_server = tornado.httpserver.HTTPServer(Application())
http_server.listen(PORT)
tornado.ioloop.IOLoop.current().start()
if __name__ == "__main__":
main()
import tornado.web
class HomeHandler(tornado.web.RequestHandler):
def get(self):
self.write({
"message": "The API server is operational."
})
class ErrorHandler(tornado.web.RequestHandler):
def prepare(self):
self.set_status(404)
self.write({
"message": "Could not find the resource requested."
})
self.finish()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.