首页 > 其他 > 详细

tornado的路由分发

时间:2019-11-30 19:57:53      阅读:163      评论:0      收藏:0      [点我收藏+]

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()

 

tornado的路由分发

原文:https://www.cnblogs.com/liuer-mihou/p/11963639.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!