码迷,mamicode.com
首页 > 其他好文 > 详细

tornado

时间:2017-04-11 01:36:16      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:blank   target   

 

《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

标签:blank   target   

原文地址:http://f1yinsky.blog.51cto.com/12568071/1914731

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!