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