0
0
Flaskframework~10 mins

Request object properties in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the HTTP method of the request.

Flask
method = request.[1]
Drag options to blanks, or click blank then click option'
Amethod_method
Bmethod_type
Cmethod_name
Dmethod
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent property like request.method_type
Trying to call request.method as a function
2fill in blank
medium

Complete the code to access the query parameters from the request.

Flask
args = request.[1]
Drag options to blanks, or click blank then click option'
Aform
Bargs
Cjson
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using request.form which is for POST form data
Using request.json which is for JSON body data
3fill in blank
hard

Fix the error in accessing JSON data from the request.

Flask
data = request.[1]()
Drag options to blanks, or click blank then click option'
Aget_json
Bjsonify
Cjson_data
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to access request.json as a method
Using request.json_data which does not exist
4fill in blank
hard

Fill 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'
Aform
Bargs
Cemail
Dusername
Attempts:
3 left
💡 Hint
Common Mistakes
Using request.args for form data
Using wrong key names that don't match the form field
5fill in blank
hard

Fill 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'
Amethod
BPOST
Cget_json
Dargs
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing method to lowercase 'post'
Using request.json as a method instead of get_json()