Skip to content

Instantly share code, notes, and snippets.

@bdarnell
Created January 22, 2014 04:12
Show Gist options
  • Save bdarnell/8553378 to your computer and use it in GitHub Desktop.
Save bdarnell/8553378 to your computer and use it in GitHub Desktop.
Example for StaticFileHandler.get_absolute_path
# For http://stackoverflow.com/questions/21248222/how-can-tornado-serve-a-single-static-file-at-an-arbitrary-location/21248691?noredirect=1#comment32053685_21248691
class MyFileHandler(StaticFileHandler):
def initialize(self, file_mapping, **kwargs):
self.file_mapping = file_mapping
super(MyFileHandler, self).initialize(**kwargs)
@classmethod
def get_absolute_path(cls, root, path):
return StaticFileHandler.get_absolute_path(root, self.file_mapping.get(path, path))
Application([
(r'/(foo.json|bar.json)', MyFileHandler,
dict(path='/dir/containing/files',
file_mapping={'foo.json': 'real_foo.json', 'bar.json': 'real_bar.json'})),
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment