Skip to content

Instantly share code, notes, and snippets.

@ento
Created April 4, 2012 16:28
Show Gist options
  • Select an option

  • Save ento/2303562 to your computer and use it in GitHub Desktop.

Select an option

Save ento/2303562 to your computer and use it in GitHub Desktop.
Given a (static) endpoint, return its actual filesystem location.
import os
from flask import current_app, request
def static_file_for(endpoint, filename=None):
if endpoint[0] == '.' and request.blueprint:
folder = current_app.blueprints[request.blueprint].static_folder
else:
folder = current_app.static_folder
return os.path.join(folder, filename) if folder else None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment