Easily use XStatic files in flask
Project description
A flask extionsion to serve xstatic files. Can be useful if you don’t use an asset pipeline and server e.g. xstatic packaged javascript files directly.
Setup
Upon initialization tell flask about the xstatic modules you want to use:
app = Flask(__name__) app.config.from_object(__name__) app.config.update(dict( XSTATIC_MODULES="jquery,d3", )) xsf = XStaticFiles(app)
Serving files
Install a minimal route handler:
@app.route('/xstatic/<module>/<path:filename>') def xstatic(module, filename): return xsf.serve_or_404(module, filename)
In your templates you can then use xstatic_url_for:
<script type=text/javascript src="{{ xstatic_url_for(module='jquery', path='jquery.min.js') }}"></script>
This has the advantage that you can later serve files from a static web server by adjusting ‘XSTATIC_ROOT’ and ‘XSTATIC_PROTO’ without having to modify any code.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for Flask-XStatic-Files-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a536fb73172ee5d9df74a2e39587217e10ff3d4dd5b5e05855287976a49050cb |
|
MD5 | 9366ca8a32120713e672216099e5c81a |
|
BLAKE2b-256 | 78f6d693f3dbc51936151caaa4e06af939387e14f11650f33bb863cacebd81dd |