Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tornado.web
- import tornado.ioloop
- class basicRequestHandler(tornado.web.RequestHandler):
- def get(self):
- self.write("Ya boi Nick made this.")
- class resourceRequestHandler(tornado.web.RequestHandler):
- def get(self, id):
- self.write("Querying tweet with id " + id)
- class queryStringRequestHandler(tornado.web.RequestHandler):
- def get(self):
- n = int(self.get_argument("n"))
- r = "odd" if n % 2 else "even"
- self.write("the number " + str(n) + " is " + r)
- class staticRequestHandler(tornado.web.RequestHandler):
- def get(self):
- self.render("index.html")
- if __name__ == "__main__":
- app = tornado.web.Application([
- (r"/", basicRequestHandler),
- (r"/blog", staticRequestHandler),
- (r"/isEven", queryStringRequestHandler),
- (r"/tweet/([0-9]+)", resourceRequestHandler)
- ])
- app.listen(8881)
- print("I'm listening on port 8881")
- tornado.ioloop.IOLoop.current().start()
- #localhost:/
- #localhost:/8881/blog
- #localhostL:8881isEven?n= number
- #localhost:8881/tweet/ id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement