Recall & Review
beginner
What is the purpose of serving CSS files in a Flask web application?
Serving CSS files allows the web app to apply styles and layouts to HTML pages, making the site visually appealing and easier to use.
Click to reveal answer
beginner
Where should CSS files be placed in a Flask project to be served correctly?
CSS files should be placed inside the 'static' folder in the Flask project directory. Flask automatically serves files from this folder.
Click to reveal answer
beginner
How do you link a CSS file in a Flask HTML template?
Use the
url_for('static', filename='style.css') function inside the href attribute of a <link> tag, like this: <br><link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">Click to reveal answer
beginner
What Flask function helps generate the URL for static files like CSS?
The
url_for() function with the first argument 'static' helps generate the correct URL path to static files such as CSS, JavaScript, or images.Click to reveal answer
intermediate
Why is it important to use
url_for('static', filename='...') instead of hardcoding the CSS file path?Using
url_for ensures the URL is correct even if the app's structure or deployment changes. It helps avoid broken links and makes the app more flexible.Click to reveal answer
Where should you place CSS files in a Flask project to serve them properly?
✗ Incorrect
Flask serves static files like CSS from the 'static' folder by default.
Which Flask function is used to generate the URL for a CSS file in a template?
✗ Incorrect
url_for with 'static' and filename generates the correct URL for static files.
What HTML tag is used to link a CSS file in a Flask template?
✗ Incorrect
The tag is used to include external CSS files in HTML.
Why should you avoid hardcoding CSS file paths in Flask templates?
✗ Incorrect
url_for ensures URLs remain correct even if the app structure changes.
If your CSS file is named 'main.css' and is inside the 'static/css' folder, how do you link it in a Flask template?
✗ Incorrect
You specify the path relative to the 'static' folder inside url_for.
Explain how to serve and link a CSS file in a Flask web application.
Think about where Flask looks for static files and how templates access them.
You got /4 concepts.
Describe the role of the 'static' folder in Flask and how it relates to serving CSS files.
Consider how Flask handles files that do not change dynamically.
You got /4 concepts.