Complete the code to serve static CSS files in Flask.
app = Flask(__name__, static_folder=[1])Flask serves static files from the folder named "static" by default. Setting static_folder="static" tells Flask where to find CSS files.
Complete the HTML code to link a CSS file named 'style.css' located in the static folder.
<link rel="stylesheet" href="{{ url_for([1], filename='style.css') }}">
In Flask, url_for('static', filename='style.css') generates the correct URL to the CSS file inside the static folder.
Fix the error in the Flask route to serve a CSS file manually.
@app.route('/css/<path:filename>') def send_css(filename): return send_from_directory([1], filename)
To serve CSS files manually, the directory path should point to the CSS folder inside the static folder, which is 'static/css'.
Fill both blanks to create a dictionary comprehension that maps CSS filenames to their sizes in bytes from the static/css folder.
css_files = {filename: os.path.getsize(os.path.join([1], filename)) for filename in os.listdir([2]) if filename.endswith('.css')}Both blanks should be 'static/css' to correctly access the CSS files folder for listing and size checking.
Fill all three blanks to create a Flask route that serves a CSS file from the static folder with caching headers.
@app.route('/styles/<path:filename>') def styles(filename): response = send_from_directory([1], filename) response.headers['Cache-Control'] = [2] response.headers['Content-Type'] = [3] return response
The CSS files are served from 'static/css'. The Cache-Control header sets caching rules, and Content-Type must be 'text/css' for CSS files.