pip install Flask-Assets python from flask import Flask from flask_assets import Environment, Bundle app = Flask(__name__) assets = Environment(app) assets.load_path = [ os.path.join(app.root_path, 'static'), os.path.join(app.root_path, 'bower_components') ] assets.directory = app.static_folder assets.url = app.static_url_path python css_bundle = Bundle( 'css/style1.css', 'css/style2.css', filters='cssmin', output='gen/packed.css' ) assets.register('css_bundle', css_bundle) python @app.route('/') def index(): return render_template('index.html') html <!DOCTYPE html> <html> <head> {% assets "css_bundle" %} <link rel="stylesheet" href="{{ ASSET_URL }}"> {% endassets %} </head> <body> <h1>Hello, Flask-Assets!</h1> </body> </html>


上一篇:
下一篇:
切换中文