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 request instead of Flask
Importing render_template when not rendering templates
Importing jsonify when not returning JSON
✗ 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
Using request instead of Flask
Forgetting to pass __name__
Calling render_template instead of Flask
✗ Incorrect
Creating the app instance requires calling Flask with the current module name.
3fill in blank
hardFix the error in the route decorator to respond to the root URL.
Flask
@app.route([1]) def home(): return "Hello, world!"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'home' or 'index' as route strings without slashes
Forgetting quotes around the route string
Using incorrect route paths
✗ Incorrect
The root URL is represented by '/' in Flask route decorators.
4fill in blank
hardFill both blanks to access the HTTP method and return it as a string.
Flask
from flask import request @app.route('/method', methods=['GET', 'POST']) def method(): return request.[1] # returns the HTTP method used # Example: if client sends POST, returns the [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using request.form or request.args which hold data, not method
Confusing method with other request attributes
✗ Incorrect
The request.method attribute holds the HTTP method as a string like 'GET' or 'POST'.
5fill in blank
hardFill all three blanks to create a dictionary response with the request path and method.
Flask
from flask import request, jsonify @app.route('/info') def info(): data = { [1]: request.[2], [3]: request.method } return jsonify(data)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted keys in dictionary
Using request.url instead of request.path
Mixing up keys and values
✗ Incorrect
The dictionary keys are strings like 'path' and 'method'. The request path is accessed via request.path.