import tornado.httpserver import tornado.ioloop import tornado.options #从命令行中读取设置 import tornado.web from tornado.options import define, options define("port", default=8000, help="run on the given port", type=int) # Tornado支持任何合法的HTTP请求(GET、POST、PUT、DELETE、HEAD、OPTIONS) class IndexHandler(tornado.web.RequestHandler): def get(self): greeting = self.get_argument('greeting', 'hello') self.write(greeting + ', 佳全') if __name__ == "__main__": tornado.options.parse_command_line() app = tornado.web.Application(handlers=[(r"/", IndexHandler)]) http_server = tornado.httpserver.HTTPServer(app) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start()
python3 1.py --port=8080 [I 220901 17:08:38 web:2271] 200 GET / (127.0.0.1) 0.88ms [I 220901 17:09:59 web:2271] 304 GET / (127.0.0.1) 0.37ms
标签:__,Web,web,tornado,创建,port,import,options From: https://www.cnblogs.com/zhouwanchun/p/16647205.html