Skip to content

Instantly share code, notes, and snippets.

@cjgiridhar
Created August 3, 2012 17:57
Show Gist options
  • Save cjgiridhar/3249999 to your computer and use it in GitHub Desktop.
Save cjgiridhar/3249999 to your computer and use it in GitHub Desktop.
Tornado - Error Handler
import tornado.ioloop
import tornado.web
import time
class ItWorks(tornado.web.RequestHandler):
def get(self):
self.write("It Works!!")
class Article(tornado.web.RequestHandler):
def get(self,id):
if id:
raise tornado.web.HTTPError(404, 'Page Not Found Error!!')
#self.send_error(500)
else:
self.write('Listing all articles\n Article1, Author1 \n Article2, Author2')
application = tornado.web.Application([
(r"/", ItWorks),
(r"/articles/(.*)", Article),
],debug=True)
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