Recall & Review
beginner
How do you serve static JavaScript files in a Flask application?
Place your JavaScript files in the 'static' folder of your Flask project. Then, use the
url_for('static', filename='yourfile.js') function in your HTML to link to the JavaScript file.Click to reveal answer
beginner
What is the default folder name Flask uses to serve static files like JavaScript?
Flask uses a folder named static by default to serve static files such as JavaScript, CSS, and images.
Click to reveal answer
beginner
Why should JavaScript files be placed in the 'static' folder in Flask?
Because Flask automatically serves files from the 'static' folder at the URL path '/static/'. This makes it easy to link JavaScript files in your HTML without extra configuration.
Click to reveal answer
beginner
How do you include a JavaScript file named 'app.js' located in the static folder in your Flask HTML template?
Use the script tag with Flask's
url_for function: <br><script src="{{ url_for('static', filename='app.js') }}"></script>Click to reveal answer
intermediate
Can you serve JavaScript files from a folder other than 'static' in Flask by default?
No, Flask serves static files only from the 'static' folder by default. To serve files from another folder, you must configure Flask explicitly.
Click to reveal answer
Where should you place JavaScript files in a Flask project to serve them easily?
✗ Incorrect
Flask serves static files like JavaScript from the 'static' folder by default.
How do you reference a JavaScript file named 'main.js' in a Flask HTML template?
✗ Incorrect
Use Flask's url_for function to generate the correct URL for static files.
What URL path does Flask use by default to serve static files?
✗ Incorrect
Flask serves static files under the '/static/' URL path by default.
If you want to serve JavaScript files from a different folder than 'static', what must you do?
✗ Incorrect
Flask requires explicit configuration to serve static files from folders other than 'static'.
Why is it important to serve JavaScript files as static files in Flask?
✗ Incorrect
Static files are served directly by Flask without extra processing, making it efficient for files like JavaScript.
Explain how to serve a JavaScript file in a Flask application and how to link it in an HTML template.
Think about where Flask looks for static files and how templates reference them.
You got /3 concepts.
Describe the default behavior of Flask regarding static files and what URL path is used to access them.
Consider the folder name and URL prefix Flask uses.
You got /3 concepts.