没有延伸StaticFileHandler
没有办法做到这一点。这将是一个微小的变化:
from tornado import gen, web
class CustomStaticFileHandler(web.StaticFileHandler):
def get(self, part1, part2, include_body=True):
# mangle path
path = "dome_{}_combined_path_{}".format(part1, part2)
# back to staticfilehandler
return super().get(path, include_body)
# if you need to use coroutines on mangle use
#
# @gen.coroutine
# def get(self, part1, part2, include_body=True):
# path = yield some_db.get_path(part1, part2)
# yield super().get(path, include_body)
app = web.Application([
(r"/foo/(.*)/bar/(.*)", CustomStaticFileHandler, {"path": "/tmp"}),
])
谢谢,这个工程。应该注意的是,您还需要重写validate_absolute_path,或者确保在处理程序声明中给出的“路径”是您将生成的每个路径的父目录。 – Gnurfos