啟動tornado項目,hello world
阿新 • • 發佈:2018-05-09
== get請求 def self. art color .com 解釋器 import
新建一個env虛擬環境
mkvirtualenv toenv
在虛擬環境中安裝tornado
workon toenv
pip install tornado
在D盤中新建tornado項目文件夾,就叫tornado。
在pycharm新建一個項目,因為pycharm沒有tornado的項目,選擇第一個python項目就好,把解釋器指向 新建的虛擬環境toenv。
新建main.py文件,輸入代碼:
# encoding: utf-8 """ @version: ?? @author: andu99 @contact: [email protected] @site: http://www.cnblogs.com/andu99/ @software: PyCharm @file: main.py @time: 2018/5/9 0009 上午 11:05""" import tornado.web import tornado.ioloop class IndexHandler(tornado.web.RequestHandler): """主頁處理類""" def get(self): """get請求""" self.write(‘hello,andu‘) if __name__ == ‘__main__‘: app = tornado.web.Application([(r"/", IndexHandler)]) app.listen(8000) tornado.ioloop.IOLoop.current().start()
運行該頁面
打開瀏覽器:
啟動tornado項目,hello world