Complete the code to add a version query parameter for cache busting in a Flask template URL.
url_for('static', filename='style.css') + '?v=[1]'
Using a timestamp as a query parameter helps browsers load the latest file version by changing the URL when the file updates.
Complete the Flask route to send a static file with a cache-busting header.
from flask import send_from_directory, make_response @app.route('/static/<path:filename>') def static_files(filename): response = make_response(send_from_directory('static', filename)) response.headers['Cache-Control'] = '[1]' return response
Setting 'no-cache, no-store, must-revalidate' tells browsers not to cache the file, ensuring fresh content.
Fix the error in the Flask template to append a file hash for cache busting.
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}?v=[1]">
The variable 'hash' should be passed from the Flask view to the template to append the file's hash for cache busting.
Fill both blanks to create a dictionary comprehension that maps filenames to their cache-busted URLs using a version number.
cache_busted_urls = {file: url_for('static', filename=file) + '?v=' + [1] for file in files if file.[2]('.css')}The dictionary comprehension appends the version to URLs only for files ending with '.css'.
Fill all three blanks to create a Flask function that returns a static file URL with a timestamp cache buster and sets a no-cache header.
from flask import url_for, make_response, send_from_directory import time def get_static_file(filename): url = url_for('static', filename=filename) + '?v=' + str([1]) response = make_response(send_from_directory('static', filename)) response.headers['Cache-Control'] = '[2]' return response, url current_time = [3]
The function uses the current integer timestamp for cache busting and sets headers to prevent caching.