快速高效的學習tornado

1.1Tornado是什麼?

Tornado是使用python編寫的一個強大的,可擴展的web服務器。他在處理嚴峻的網絡流量是表現的足夠強健,但卻在創建和編寫時有着足夠的輕量級,並能夠被用在大量的應用和工具中。
底層基於協程+epoll

1.1.1 Tornado入門

簡單編寫一個Hello Word

hello.py

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

class IndexHandlenr(tornado.web.RequestHandler):
    def get(self):
        self.write('hello word')

if __name__ == '__main__':
    appliectin = tornado.web.Application([
        (r'/',IndexHandlenr)
    ])
    appliectin.listen(8003)
    tornado.ioloop.IOLoop.current().start()

你可以在命令行裏嘗試運行這個程序已測試輸出:

python hello.py --port=8003

現在你可以在瀏覽器中打開http://localhost:8003,或者打開另一個終端窗口使用curl測試我們的應用:

$ curl http://localhost:8000/
Hello, friendly user!
$ curl http://localhost:8000/?greeting=Salutations
Salutations, friendly user!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章