1
from tornado.httpserver import HTTPServer from tornado.routing import RuleRouter, Rule, PathMatches from tornado.web import RequestHandler, Application from tornado.ioloop import IOLoop class Handler1(RequestHandler): def get(self): self.write(‘1‘) class Handler2(RequestHandler): def get(self): self.write(‘2‘) app1 = Application([ (r"/app1/handler", Handler1), # other handlers ... ]) app2 = Application([ (r"/app2/handler", Handler2), # other handlers ... ]) router = RuleRouter([ Rule(PathMatches("/app1.*"), app1), Rule(PathMatches("/app2.*"), app2) ]) if __name__ == ‘__main__‘: server = HTTPServer(router) server.listen(8888) IOLoop.current().start()
原文:https://www.cnblogs.com/liuer-mihou/p/11963639.html