Tornado安裝
pip install tornado
寫個hello:程序名app.py
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("hello world")
application = tornado.web.Application([
(r"/",MainHandler)],
)
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
MainHandler作爲入口,是一個類,繼承了RequestHandler,get函數定義輸出的字符。如果寫爲<h1>Hello, world 你</h1> 輸出就變爲H1標記包含的字符了。windows下如果顯示中文似乎已經不必再在文件的開頭聲明 #code:utf-8 可能因爲python 3都是用unicode字符?
使用python app.py運行,寫爲別的名字也可以,但是windows裏爲什麼不能ctrl+c停止呢?