Tornado第一个程序

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停止呢?

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章