在不同的端点上提供两个不同的静态文件
Serve two different static files on different endpoints
我有一个简单的龙卷风服务器,默认情况下显示 index.html - 这有效。但是我还想为 localhost/default 端点渲染一个 json 文件,当我转到 localhost:8000/default 时它会抛出一个错误 (TypeError: get() missing 1 required positional argument: 'path').
这是应用程序配置。
application = tornado.web.Application([
(r"/", MainHandler),
(r"/login", LoginHandler),
(r"/getToken", TokenHandler),
(r"/default", tornado.web.StaticFileHandler, {"path": root, "default_filename": "test.json"}),
(r"/(.*)", tornado.web.StaticFileHandler, {"path": root, "default_filename": "index.html"}),
])
文档指出:
Note that a capture group in the regex is required to parse the value for the path argument to the get() method
这意味着您需要在url中定义一个正则表达式组来捕获请求的路径。
示例:
(r"/default/(.*)", ...)
我有一个简单的龙卷风服务器,默认情况下显示 index.html - 这有效。但是我还想为 localhost/default 端点渲染一个 json 文件,当我转到 localhost:8000/default 时它会抛出一个错误 (TypeError: get() missing 1 required positional argument: 'path').
这是应用程序配置。
application = tornado.web.Application([
(r"/", MainHandler),
(r"/login", LoginHandler),
(r"/getToken", TokenHandler),
(r"/default", tornado.web.StaticFileHandler, {"path": root, "default_filename": "test.json"}),
(r"/(.*)", tornado.web.StaticFileHandler, {"path": root, "default_filename": "index.html"}),
])
文档指出:
Note that a capture group in the regex is required to parse the value for the path argument to the get() method
这意味着您需要在url中定义一个正则表达式组来捕获请求的路径。
示例:
(r"/default/(.*)", ...)