import tornado.ioloop
import tornado.web
import tornado.httpserver
import tornado.options
from tornado.options import define, options
#定义端口配置
define('port', type=int, default=8080)
#创建视图处理器
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("<h1>hello,world</h1>")
#创建路由表
urls = [(r"/", MainHandler),]
#创建配置-开启调试模式
configs = dict(debug=True)
#自定义应用
class MyApplication(tornado.web.Application):
def __init__(self, urls, configs):
super(MyApplication, self).__init__(handlers=urls, **configs)
#创建服务器
def make_app():
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(MyApplication(urls,configs))
http_server.listen(options.port)
tornado.ioloop.IOLoop.current().start()
#启动服务器
if __name__ == '__main__':
make_app()
Tornado之hello world
猜你喜欢
转载自blog.csdn.net/weixin_42694291/article/details/83622482
今日推荐
周排行