Recall & Review
beginner
What is the purpose of the
static folder in a Flask project?The
static folder holds files like images, CSS, and JavaScript that the browser can load directly. It keeps these files separate from Python code for better organization.Click to reveal answer
beginner
How do you reference a static file in a Flask HTML template?
Use the
url_for('static', filename='path/to/file') function. For example, <img src="{{ url_for('static', filename='images/logo.png') }}"> loads an image from the static folder.Click to reveal answer
beginner
Why should static files be organized into subfolders like
css, js, and images inside the static folder?Organizing static files into subfolders helps keep the project tidy and makes it easier to find and manage files, just like sorting your documents into labeled folders at home.
Click to reveal answer
beginner
What happens if you place a CSS file outside the
static folder in Flask?Flask will not serve the CSS file automatically, so the browser won’t load it. Static files must be inside the
static folder to be accessible via URLs.Click to reveal answer
intermediate
How can you customize the static folder location in a Flask app?
You can set the
static_folder parameter when creating the Flask app, like app = Flask(__name__, static_folder='assets'). This changes where Flask looks for static files.Click to reveal answer
Where should you put JavaScript files in a Flask project?
✗ Incorrect
JavaScript files belong in the
static/js folder so Flask can serve them as static content.How do you link a CSS file named
style.css located in static/css in a Flask template?✗ Incorrect
Use
url_for('static', filename='css/style.css') to generate the correct URL for static files.What is the default name of the folder Flask uses to serve static files?
✗ Incorrect
By default, Flask serves static files from the
static folder.If you want to change the static folder to
assets, how do you do it?✗ Incorrect
You specify the static folder when creating the Flask app with
static_folder='assets'.Why is it important to keep static files separate from Python code in Flask?
✗ Incorrect
Separating static files keeps the project organized and allows browsers to load these files directly.
Explain how to organize and reference static files in a Flask project.
Think about how you keep your desk tidy with folders and labels.
You got /3 concepts.
Describe what happens if a static file is placed outside the
static folder in Flask.Imagine trying to find a book that is not on the shelf where you expect it.
You got /3 concepts.