首页 > 代码库 > tornado

tornado

 

《introduction-to-tornado》笔记

http://docs.pythontab.com/tornado/introduction-to-tornado/index.html

 

1、安装tornado

$ curl -L -O https://github.com/facebook/tornado/archive/v3.1.0.tar.gz

$ tar xvzf v3.1.0.tar.gz

$ cd tornado-3.1.0

$ python setup.py build

$ sudo python setup.py install

验证安装成功:

[root@localhost ~]# ipython

In [1]: import tornado

 

2、Hello Tornado

代码清单1-1 基础:hello.py

import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web

#Tornado包括了一个有用的模块(tornado.options)来从命令行中读取设置。
#我们在这里使用这个模块指定我们的应用监听HTTP请求的端口。
#它的工作流程如下:如果一个与define语句中同名的设置在命令行中被给出,那么它将成为全局options的一个属性。
from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)

class IndexHandler(tornado.web.RequestHandler):
    def get(self):
        greeting = self.get_argument(‘greeting‘, ‘Hello‘)
        self.write(greeting + ‘, friendly user!‘)

if __name__ == "__main__":
    tornado.options.parse_command_line()
    app = tornado.web.Application(handlers=[(r"/", IndexHandler)])
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()
$ python hello.py --port=8000
验证:
在浏览器中打开http://localhost:8000
或者

[cxiong@localhost ~]$ curl http://localhost:8000/
Hello, friendly user![cxiong@localhost ~]$ curl http://localhost:8000/?greeting=Salutations
Salutations, friendly user![cxiong@localhost ~]$


 

3、
 
 
========================================================================================================
 
http://www.tornadoweb.org
 

《tornado概览》

http://www.tornadoweb.cn/documentation

 

《python与tornado》-现代魔法学院

http://www.nowamagic.net/academy/part/13/325

 

《tornado框架》

http://www.cnblogs.com/kongqi816-boke/p/5699866.html#_labelTop

tornado