1. 程式人生 > >啟動tornado項目,hello world

啟動tornado項目,hello world

== 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