0
0
Flaskframework~20 mins

Static file organization in Flask - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Static File Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1:30remaining
Serving static CSS files in Flask
You have a Flask app with a CSS file located at static/css/style.css. What URL path will Flask use to serve this CSS file by default?
A/assets/css/style.css
B/css/style.css
C/static/css/style.css
D/public/css/style.css
Attempts:
2 left
💡 Hint
Flask serves files from the static folder under the /static/ URL prefix by default.
📝 Syntax
intermediate
1:30remaining
Referencing static images in Flask templates
In a Flask Jinja2 template, which is the correct way to reference an image file named logo.png inside the static/images folder?
A<img src="{{ url_for('static', filename='images/logo.png') }}" alt="Logo">
B<img src="/images/logo.png" alt="Logo">
C<img src="{{ static('images/logo.png') }}" alt="Logo">
D<img src="{{ url_for('images', filename='logo.png') }}" alt="Logo">
Attempts:
2 left
💡 Hint
Use Flask's url_for function with the 'static' endpoint to generate URLs for static files.
🔧 Debug
advanced
2:00remaining
Static file not found error in Flask
You placed a JavaScript file app.js inside static/js/ but when accessing /static/js/app.js in the browser, you get a 404 error. Which of the following is the most likely cause?
AThe URL should be <code>/js/app.js</code> instead of <code>/static/js/app.js</code>.
BThe Flask app is missing the <code>static_url_path</code> parameter in <code>Flask()</code> constructor.
CThe <code>app.js</code> file has incorrect file permissions and cannot be read.
DThe <code>static</code> folder is not in the same directory as the Flask app script.
Attempts:
2 left
💡 Hint
Flask serves static files relative to the location of the app script by default.
state_output
advanced
1:30remaining
Effect of changing static_url_path in Flask
If you create a Flask app with app = Flask(__name__, static_url_path='/assets') and place a file logo.png inside static/, what URL path will serve this file?
A/assets/static/logo.png
B/assets/logo.png
C/logo.png
D/static/logo.png
Attempts:
2 left
💡 Hint
The static_url_path changes the URL prefix for static files.
🧠 Conceptual
expert
2:30remaining
Best practice for organizing static files in Flask
Which of the following is the best practice for organizing static files in a Flask project to keep it maintainable and scalable?
AOrganize static files into subfolders like <code>css/</code>, <code>js/</code>, and <code>images/</code> inside <code>static/</code>.
BPlace all static files directly inside the <code>static/</code> folder without subfolders.
CStore static files outside the Flask project and serve them with a separate web server only.
DUse a single large CSS and JS file placed in the root project folder.
Attempts:
2 left
💡 Hint
Think about clarity and ease of finding files as your project grows.