1.Tornado下载:https://pypi.python.org/pypi/tornado/ 下载最新的
2.解压和安装:
tar xf
cd
python setup.py install
3.tornado例子:
import tornado.ioloopimport tornado.webclass MainHandler(tornado.web.RequestHandler): def get(self): self.write("Hello, world")class URLGetsHandler(tornado.web.RequestHandler): def get(self): post_data = {} strTmp = '' #key = '' args = self.request.arguments for key in args: post_data[key] = self.get_argument(key) strTmp = strTmp + "%s = %s "%(key, post_data[key]) print('%s = %s '%(key, post_data[key])) self.write(strTmp)class TestGetHandler(tornado.web.RequestHandler): def get(self): id = self.get_argument('id','0') if 0 == len(id) : self.write("id = 0") else: self.write("id = %s"%(id)) def post(self,data): self.write(data)def make_app(): return tornado.web.Application([ (r"/", MainHandler), (r"/TestGet", TestGetHandler), (r"/URLGets", URLGetsHandler), ], debug=True)if __name__ == "__main__": app = make_app() app.listen(8888) tornado.ioloop.IOLoop.current().start()