如何开启Tornado的调试模式

2025-03-31 23:40:44
推荐回答(1个)
回答1:

开启调试模式需要 import 一个模块即可,import tornado.autoreload
将修改的文件上传之后,不需要再重启,修改的结果就会显示出来了,另外也可以在 settings 加入 debug选项:
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
settings = {'debug' : True}
define("debug",default=True,help="Debug Mode",type=bool)
def main():
tornado.options.parse_command_line()
application = tornado.web.Application([
(r"/", MainHandler),
(r"/nowamagic/", NowaMagicHandler),
],**settings)
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start().