Change static folder from config in Flask

app = Flask(__name__, static_url_path="/STATIC_FOLDER", static_folder='STATIC_FOLDER')

I don't know anything about that snippet, but

some_function(...) = some_value

is never valid Python (Python doesn't have l-values). It looks like config has a dict-like interface, so the offending line should probably just be

self.config['STATIC_FOLDER'] = value

Probably a copy-and-paste error from the getter definition above the setter.


Okay, I assume you want to use a custom path to the static folder for whatever reason. I wanted to do the same for the sake of better app modularity.

Here's my app folder structure:

instance/
core/
  |_templates/
  |_static/
  |_views.py
run.py
config.py

As you can see, my static folder is inside the core folder.

In run.py, you can do the following:

app = Flask(__name__, static_url_path=None)

if __name__ == '__main__':
    app.config.from_object('config')

    # config file has STATIC_FOLDER='/core/static'
    app.static_url_path=app.config.get('STATIC_FOLDER')

    # set the absolute path to the static folder
    app.static_folder=app.root_path + app.static_url_path

    print(app.static_url_path)
    print(app.static_folder)

    app.run(
        host=app.config.get('HOST'),
        port=app.config.get('PORT'),
        threaded=True
        )

This is what I did, and it works perfectly fine. I'm using flask 0.12.