天天看點

python tornado簡單示例

python tornado簡單示例

import tornado.ioloop
import tornado.web


class MainHandler(tornado.web.RequestHandler):
    """該函數負責相應定位到該RequestHandler的HTTP GET請求的處理"""
    def get(self):
        self.write("Hello World")


def make_app():
    """函數傳回web.Application對象,URL的通路映射到了RequestHandler子類MainHandler中"""
    return tornado.web.Application([(r"/", MainHandler), ])


def main():
    """http://localhost:8888"""
    app = make_app()
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()


if __name__ == "__main__":
    main()