Created
January 22, 2014 04:12
-
-
Save bdarnell/8553378 to your computer and use it in GitHub Desktop.
Example for StaticFileHandler.get_absolute_path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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