Complete the code to serve static files in Flask.
app = Flask(__name__, static_folder=[1])Flask uses the folder named static by default to serve static files like CSS and images.
Complete the code to link a CSS file named style.css located in the static folder inside an HTML template.
<link rel="stylesheet" href="{{ url_for('static', filename=[1]) }}">
The url_for('static', filename='style.css') function generates the correct URL for the file style.css inside the static folder.
Fix the error in the Flask route to serve a static image named logo.png from the static folder.
@app.route('/logo') def logo(): return send_from_directory([1], 'logo.png')
The send_from_directory function needs the folder name where static files are stored, which is static in Flask.
Fill both blanks to create a dictionary comprehension that maps filenames to their sizes for all files in the static folder.
import os files = {f: os.path.getsize(os.path.join([1], f)) for f in os.listdir([2])}
Both blanks should be the static folder name because we want to list and get sizes of files inside the static folder.
Fill all three blanks to create a Flask route that serves a static CSS file from a subfolder named 'css' inside the static folder.
@app.route('/custom-style') def custom_style(): return send_from_directory(os.path.join([1], [2]), [3])
The send_from_directory function needs the path to the 'css' subfolder inside 'static' and the filename 'style.css' to serve the CSS file correctly.