zoukankan      html  css  js  c++  java
  • tornado实现不同app路由分发

    tornado实现app路由分发

    from tornado import ioloop
    from tornado.httpserver import HTTPServer
    from tornado.web import Application, RequestHandler
    from tornado.routing import RuleRouter, PathMatches, Rule
    
    
    class Handler1(RequestHandler):
        def get(self):
            self.write('hello')
    
    
    class Handler2(RequestHandler):
        def get(self):
            self.write('world')
    
    
    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)
    ])
    
    server = HTTPServer(router)
    
    if __name__ == '__main__':
        server = HTTPServer(router)
        server.listen(8000)  # 改用服务器进行监听
        ioloop.IOLoop.current().start()
    

    这样就可以将不同的app整合到一个router下面, 将整个项目划分成各个小模块来管理

  • 相关阅读:
    软件工程实践总结-黄紫仪
    beta冲刺总结附(分工)-咸鱼
    beta冲刺总结-咸鱼
    beta冲刺7-咸鱼
    beta冲刺用户测评-咸鱼
    beta冲刺6-咸鱼
    beta冲刺5-咸鱼
    beta冲刺4-咸鱼
    beta冲刺3-咸鱼
    beta冲刺2-咸鱼
  • 原文地址:https://www.cnblogs.com/ivy-blogs/p/11735060.html
Copyright © 2011-2022 走看看