之前一直稳定运行的代码,我引进新项目的时候,忽然报错
'Application' object has no attribute 'handlers'"
困扰许久。而且是时而正常,时而出错。
。
无法忍受,后开启debug模式排查,发现原来是tornado4.5起升级了,引入了新的tornado.routing模块。
4.4的Application代码如下:
class Application(httputil.HTTPServerConnectionDelegate):
"""A collection of request handlers that make up a web application.
``static_handler_class`` setting.
"""
def __init__(self, handlers=None, default_host="", transforms=None,
**settings):
if transforms is None:
self.transforms = []
if settings.get("compress_response") or settings.get("gzip"):
self.transforms.append(GZipContentEncoding)
else:
self.transforms = transforms
self.handlers = []
self.named_handlers = {}
self.default_host = default_host
self.settings = settings
self.ui_modules = {'linkify': _linkify,
'xsrf_form_html': _xsrf_form_html,
'Template': TemplateModule,
}
self.ui_methods = {}
self._load_ui_modules(settings.get("ui_modules", {}))
self._load_ui_methods(settings.get("ui_methods", {}))
if self.settings.get("static_path"):
path = self.settings["static_path"]
handlers = list(handlers or [])
static_u