Serve custom bootstrap from a subdirectory within static?
I'm trying to serve a custom version of bootstrap (basically a different theme) from the subdirectory custom_bootstrap within the application's static folder:
├── __init__.py
└── static
└── custom_bootstrap
├── css
├── fonts
└── js
The following config settings are used for flask-bootstrap:
BOOTSTRAP_SERVE_LOCAL = True
In the app, the StaticCDN is used:
# …
Bootstrap(app)
app.extensions['bootstrap']['cdns']['bootstrap'] = StaticCDN()
#…
The above serves the custom bootstrap from static/{css,js,fonts}. Setting the static_endpoint parameter of StaticCDN to something like 'static.custom_bootstrap' yields a routing error. Is there anything I'm missing here?
I had the same problem and figured out the following "solution":
First, i added a view to serve my custom bootstrap dir...
@app.route('/static/bootstrap_custom/<path:filename>')
def serve_bootstrap_custom(filename):
return app.send_static_file('bootstrap_custom/' + filename)
And second, i set up a StaticCDN with the new view as static_endpoint as the CDN for bootstrap ...
app.extensions['bootstrap']['cdns']['bootstrap'] = StaticCDN(static_endpoint='serve_bootstrap_custom')
This works, but i'm not sure if this is the intended way to do it. If there is a better way, i would love to know about that.