pip install Flask-Assets
python
from flask_assets import Environment, Bundle
python
app = Flask(__name__)
assets = Environment(app)
python
css_bundle = Bundle('path/to/file1.css', 'path/to/file2.css', output='gen/styles.css')
js_bundle = Bundle('path/to/file1.js', 'path/to/file2.js', output='gen/scripts.js')
python
assets.register('css_all', css_bundle)
assets.register('js_all', js_bundle)
html
{% assets "css_all" %}
<link rel="stylesheet" href="{{ ASSET_URL }}">
{% endassets %}
html
{% assets "js_all" %}
<script src="{{ ASSET_URL }}"></script>
{% endassets %}
python
from flask import Flask, render_template
from flask_assets import Environment, Bundle
app = Flask(__name__)
assets = Environment(app)
css_bundle = Bundle('path/to/file1.css', 'path/to/file2.css', output='gen/styles.css')
js_bundle = Bundle('path/to/file1.js', 'path/to/file2.js', output='gen/scripts.js')
assets.register('css_all', css_bundle)
assets.register('js_all', js_bundle)
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run()