1
0
Fork
You've already forked flask-multistatic
0
Simple flask plugin to add support for overriding static files. Retrieved from https://pagure.io/fork/underscore/flask-multistatic
  • Python 100%
2024年04月11日 18:34:24 +00:00
.gitignore Remove trailing slash 2016年02月11日 10:49:44 +01:00
example.conf Add apache example 2015年07月21日 16:17:34 +02:00
flask_multistatic.py Change 'cache_timeout' to 'max_age' and increment version number. 2024年04月11日 16:51:37 +02:00
LICENSE Add the LICENSE file 2015年03月19日 16:36:10 +01:00
MANIFEST.in Add a MANIFEST.in file to include some of the metadata files 2016年02月11日 11:05:20 +01:00
README.rst Add apache example 2015年07月21日 16:17:34 +02:00
setup.py Increment version according to Semantic Versioning 2024年04月11日 18:34:24 +00:00

flask-multistatic

Author

Pierre-Yves Chibon <pingou@pingoured.fr>

This project is a simple flask plugin to add support for overriding static files.

Dependencies:

The dependency list is therefore:

Usage:

In your flask application:

import flask
from flask_multistatic import MultiStaticFlask

And replace the way you build you flask application from

APP = flask.Flask(__name__)

by

APP = MultiStaticFlask(__name__)

You can then specify multiple folder where static files are located, for example:

APP.static_folder = [
 os.path.join(APP.root_path, 'static', APP.config['THEME_FOLDER']),
 os.path.join(APP.root_path, 'static', 'default')
]

Note

The order of the folder is important, the last folder should be the one where most files are present, the other folders are where you override the static files. So in the example above, all the default static files are in /static/default/ and the files specific for one theme are under /static/<theme_name>/.

Production:

Note that this is most likely less efficient than having apache serve the static files itself, but even if you do that you might want to have multiple static directories and have apache fallback.

In this case, you can use the example.conf file that is shipped as part of this repository.

The example.conf file has an example configuration that will try to serve a file from an instance-specific theme directory, and only if the file was not found, fall back to the application default theme.

License:

This project is licensed GPLv3+.