What is the purpose of the static folder in a Flask application?
The static folder holds files like images, CSS, and JavaScript that the browser can load directly. It helps keep these files organized and accessible.
Click to reveal answer
beginner
How do you tell Flask where your static folder is located?
You can set the static folder location by passing the static_folder parameter when creating the Flask app, like Flask(__name__, static_folder='my_static').
Click to reveal answer
beginner
What is the default URL path to access static files in Flask?
By default, Flask serves static files under the URL path /static/. For example, a file style.css in the static folder is accessed at /static/style.css.
Click to reveal answer
intermediate
How can you change the URL path prefix for static files in Flask?
You can change the URL path prefix by setting the static_url_path parameter when creating the Flask app, like Flask(__name__, static_url_path='/assets'). Then static files are accessed under /assets/.
Click to reveal answer
beginner
Why is it important to keep static files in a separate folder in Flask?
Keeping static files separate helps organize your project, makes it easier for browsers to cache files, and allows Flask to serve them efficiently without running Python code.
Click to reveal answer
What is the default folder name Flask uses to serve static files?
Aassets
Bpublic
Cstatic
Dresources
✗ Incorrect
Flask uses the folder named 'static' by default to serve static files.
How do you change the folder Flask uses for static files?
AModify the config file named static.conf
BRename the 'templates' folder
CChange the app route decorator
DSet the static_folder parameter when creating the Flask app
✗ Incorrect
You change the static folder by passing static_folder='folder_name' when creating the Flask app.
If you want static files to be accessed at '/assets/', which parameter should you set?
Aurl_prefix='/assets'
Bstatic_url_path='/assets'
Cstatic_folder='/assets'
Dstatic_route='/assets'
✗ Incorrect
The static_url_path parameter changes the URL prefix for static files.
Which of these files would you put in the static folder?
Astyle.css
Bapp.py
Cindex.html
Ddatabase.db
✗ Incorrect
CSS files like style.css belong in the static folder to be served directly to browsers.
What URL would you use to access 'logo.png' inside the default static folder?
A/static/logo.png
B/logo.png
C/assets/logo.png
D/files/logo.png
✗ Incorrect
By default, static files are accessed under '/static/', so the URL is '/static/logo.png'.
Explain how to configure a custom static folder and URL path in a Flask app.
Think about the parameters you pass when creating the Flask app object.
You got /3 concepts.
Why should static files be separated from templates and Python code in Flask?
Consider how browsers and servers handle static files differently from dynamic content.
You got /4 concepts.
Practice
(1/5)
1. What is the default folder name Flask uses to serve static files like images and CSS?
easy
A. assets
B. static
C. public
D. files
Solution
Step 1: Recall Flask default static folder
Flask by default looks for a folder named static in your project to serve static files.
Step 2: Confirm other options are not defaults
Folders like assets, public, or files are common in other frameworks but not Flask's default.
Final Answer:
static -> Option B
Quick Check:
Default static folder = static [OK]
Hint: Remember Flask uses 'static' folder by default for static files [OK]
Common Mistakes:
Confusing 'assets' or 'public' as default static folder
Thinking Flask serves static files from root directory
Assuming no default static folder exists
2. Which of the following is the correct way to change the static folder name to 'assets' when creating a Flask app?
easy
A. app = Flask(__name__, static='assets')
B. app = Flask(static_folder='assets')
C. app = Flask(__name__, static_folder='assets')
D. app = Flask(__name__, static_url_path='assets')