沒有延伸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