Challenge - 5 Problems
Static Folder Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the URL to access a static file?
Given a Flask app with the default static folder named 'static', what URL path will serve the file located at
static/images/logo.png?Flask
from flask import Flask app = Flask(__name__) # File located at static/images/logo.png @app.route('/') def home(): return 'Home Page' if __name__ == '__main__': app.run()
Attempts:
2 left
💡 Hint
Flask serves static files from the folder named 'static' by default under the '/static' URL prefix.
✗ Incorrect
By default, Flask serves files inside the 'static' folder under the URL path '/static'. So a file at 'static/images/logo.png' is accessed via '/static/images/logo.png'.
📝 Syntax
intermediate2:00remaining
How to change the static folder name in Flask?
Which code snippet correctly changes the static folder from the default 'static' to 'assets' in a Flask app?
Attempts:
2 left
💡 Hint
The parameter to set the folder name is 'static_folder'.
✗ Incorrect
To change the folder where Flask looks for static files, use the static_folder parameter when creating the Flask app.
🔧 Debug
advanced2:00remaining
Why does Flask not serve static files from a custom folder?
A developer sets
app = Flask(__name__, static_folder='public') but accessing /public/style.css returns 404. What is the cause?Attempts:
2 left
💡 Hint
Changing the folder does not change the URL path unless you also set static_url_path.
✗ Incorrect
When you change the static folder to 'public', Flask still serves static files under '/static' URL by default. To serve files under '/public', you must set static_url_path='/public'.
❓ state_output
advanced2:00remaining
What is the value of static_url_path after app creation?
Given
app = Flask(__name__, static_folder='assets', static_url_path='/content'), what is the value of app.static_url_path?Flask
from flask import Flask app = Flask(__name__, static_folder='assets', static_url_path='/content') print(app.static_url_path)
Attempts:
2 left
💡 Hint
static_url_path sets the URL prefix for static files.
✗ Incorrect
The static_url_path parameter sets the URL prefix for static files. Here it is '/content'.
🧠 Conceptual
expert2:00remaining
Why use a custom static_url_path in Flask?
Which reason best explains why a developer might set a custom
static_url_path different from the default '/static'?Attempts:
2 left
💡 Hint
Think about URL naming conflicts in web apps.
✗ Incorrect
Changing static_url_path helps avoid conflicts if another route or external service uses '/static'. It does not affect performance or compression.