classqueryStringRequestHandler(tornado.web.RequestHandler): defget(self): n = int(self.get_argument('n')) result = 'odd'if n % 2else'even' self.write('ths number {} is {}'.format(n,result)) classresourceRequestHandler(tornado.web.RequestHandler): defget(self, mid): self.write("Hey we got id: {}".format(mid))
defmain(): app = tornado.web.Application([ (r'/', basicRequestHandler), (r'/static', staticRequestHandler), (r'/query', queryStringRequestHandler), (r'/resource/([0-9]+)', resourceRequestHandler) ]) app.listen(8081) print('server is turn on and listening port 8081') tornado.ioloop.IOLoop.current().start() if __name__ == "__main__": main()