bash
pip install Flask-Assets
python
from flask_assets import Bundle, Environment
bundles = {
'my_css_bundle': Bundle(
'css/style1.css',
'css/style2.css',
filters='cssmin',
output='gen/packed.css'
),
'my_js_bundle': Bundle(
'js/script1.js',
'js/script2.js',
filters='jsmin',
output='gen/packed.js'
)
}
assets = Environment()
def init_app(app):
assets.init_app(app)
app.config['ASSETS_DEBUG'] = False
assets.register(bundles)
python
from flask import Flask, render_template
from config import init_app
app = Flask(__name__)
init_app(app)
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run()
html
<!DOCTYPE html>
<html>
<head>
{% assets "my_css_bundle" %}
<link rel="stylesheet" type="text/css" href="{{ ASSET_URL }}">
{% endassets %}
</head>
<body>
<h1>Welcome to Flask-Assets</h1>
{% assets "my_js_bundle" %}
<script src="{{ ASSET_URL }}"></script>
{% endassets %}
</body>
</html>