Flask: Static files in subdirectories Flask: Static files in subdirectories flask flask

Flask: Static files in subdirectories


Dont set the script name to a blank string, try setting it to '/projects/test'. By setting SCRIPT_NAME to a blank string the application thinks its running on the root of the domain, so routes generated by url_for will start there. With a script name of '/projects/test', url_for('static', filename='/foo/bar.css') will return '/projects/test/static/foo/bar.css'

If you genuinely want your apps static media served on a different endpoint then you'll just have to roll it yourself, something like this:

from flask import Flaskfrom os.path import joinapp = Flask(__name__)def url_for_static(filename):    root = app.config.get('STATIC_ROOT', '')    return join(root, filename)