Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Flask class.
Flask
from flask import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing render_template instead of Flask
Using incorrect module name
✗ Incorrect
The Flask class is imported from the flask module to create the app.
2fill in blank
mediumComplete the code to create a Flask app instance.
Flask
app = [1](__name__) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling render_template instead of Flask
Forgetting to pass __name__
✗ Incorrect
Creating the app instance requires calling Flask with __name__.
3fill in blank
hardFix the error in the route decorator to serve JavaScript files.
Flask
@app.route('/static/[1]')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using angle brackets incorrectly
Missing 'path:' prefix
✗ Incorrect
Using <path:filename> allows Flask to capture the full path including folders.
4fill in blank
hardFill both blanks to send a JavaScript file from the static folder.
Flask
return [1]('static', filename=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using send_file without folder path
Passing wrong variable name for filename
✗ Incorrect
send_from_directory sends files from a folder; filename is the file name variable.
5fill in blank
hardFill all three blanks to define a route that serves JavaScript files correctly.
Flask
@app.route('/js/[1]') def serve_js([2]): return [3]('static/js', filename=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching route and function parameter names
Using send_file without folder path
✗ Incorrect
The route captures 'filename', the function parameter is 'file', and send_from_directory serves the file from 'static/js'.