Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to get the HTTP method of the request.
Flask
method = request.[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent property like request.method_type
Trying to call request.method as a function
✗ Incorrect
The request.method property returns the HTTP method used (GET, POST, etc.).
2fill in blank
mediumComplete the code to access the query parameters from the request.
Flask
args = request.[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using request.form which is for POST form data
Using request.json which is for JSON body data
✗ Incorrect
The request.args property contains the URL query parameters as a dictionary-like object.
3fill in blank
hardFix the error in accessing JSON data from the request.
Flask
data = request.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to access request.json as a method
Using request.json_data which does not exist
✗ Incorrect
The correct method to parse JSON body data is request.get_json().
4fill in blank
hardFill both blanks to get a form value safely with a default.
Flask
username = request.[1].get('[2]', 'guest')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using request.args for form data
Using wrong key names that don't match the form field
✗ Incorrect
Use request.form.get('username', 'guest') to get the form field 'username' with a default value.
5fill in blank
hardFill all three blanks to check if the request method is POST and get JSON data.
Flask
if request.[1] == '[2]': data = request.[3]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing method to lowercase 'post'
Using request.json as a method instead of get_json()
✗ Incorrect
Check request.method == 'POST' and then get JSON data with request.get_json().