标题 ##最近刚开通了博客,有些不完善的地方,以后会越来越好
下面是一个最简单的Tornado实例:
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("hello tornado")
application = tornado.web.Application(
[
(r"/index",MainHandler),
]
)
if __name__ == "__main__":
application.listen(8080)
tornado.ioloop.IOLoop.instance().start()
下面,我们将以上的代码在我的服务器上运行:
python test1.py
接下来打开服务器,输入以下url:
127.0.0.1:8080/index
页面就会把self.write("hello tornado")
里面的内容打印到客户端上面。