Skip to content

Instantly share code, notes, and snippets.

@erikrose
Created March 8, 2013 19:03
Show Gist options
  • Save erikrose/5118928 to your computer and use it in GitHub Desktop.
Save erikrose/5118928 to your computer and use it in GitHub Desktop.
@dxr_blueprint.route('/<path:tree_and_path>')
def browse(tree_and_path):
"""Show a directory listing or a single file from one of the trees."""
tree, _, path = tree_and_path.partition('/')
tree_folder = os.path.join(current_app.instance_path, 'trees', tree)
if isdir(os.path.join(tree_folder, path)):
# It's a bare directory. Add the index file to the end:
path = os.path.join(path, current_app.config['DIRECTORY_INDEX'])
else:
# It's a file. Add the .html extension:
path += '.html'
return send_from_directory(tree_folder, path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment