url_for('static', filename='style.css') generate?In a Flask app, you use url_for('static', filename='style.css') inside a template. What URL will this produce by default?
Think about the default folder Flask uses for static files.
Flask serves static files from the /static URL path by default. So url_for('static', filename='style.css') returns /static/style.css.
url_for call correctly references a static image?Choose the correct Flask url_for syntax to get the URL for logo.png inside the static/images folder.
Remember the filename argument is a relative path inside the static folder.
The filename parameter should be the relative path inside the static folder without a leading slash. Option C is correct.
url_for('static', filename='css/style.css') return 404?You have a file at project/static/css/style.css. Your template uses url_for('static', filename='css/style.css') but the browser shows a 404 error. What is the most likely cause?
Check if the static folder location matches Flask's configuration.
Flask serves static files from the folder named 'static' by default. If the folder is renamed or moved, the URL will 404. The filename can include subfolders and should not start with a slash. Flask serves static files automatically from the static folder.
Given this Flask template code:
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">And the app is running with default static folder, what will the rendered HTML look like?
Remember how url_for builds URLs for static files.
The url_for('static', filename='css/main.css') call generates the URL /static/css/main.css. So the rendered HTML uses that URL in the href attribute.
url_for?You want Flask to serve static files from a folder named assets instead of the default static. Which setup and url_for usage is correct?
Check Flask's static_folder parameter and how url_for references static files.
To serve static files from a custom folder, set static_folder='assets' when creating the Flask app. The url_for call still uses 'static' as the endpoint name. Option A is correct.