0
0
Flaskframework~10 mins

Accessing form data 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 value of 'username' from the form data.

Flask
username = request.form.get('[1]')
Drag options to blanks, or click blank then click option'
Aname
Buser
Cid
Dusername
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong field name like 'user' or 'name' instead of 'username'.
Forgetting to use quotes around the field name.
2fill in blank
medium

Complete the code to check if the form was submitted using POST method.

Flask
if request.method == '[1]':
Drag options to blanks, or click blank then click option'
AGET
BPOST
CPUT
DDELETE
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GET' instead of 'POST' to check the form submission.
Using lowercase method names instead of uppercase.
3fill in blank
hard

Fix the error in the code to correctly access the 'email' field from the form data.

Flask
email = request.[1]['email']
Drag options to blanks, or click blank then click option'
Aform
Bjson
Cvalues
Dargs
Attempts:
3 left
💡 Hint
Common Mistakes
Using request.args which is for URL parameters.
Using request.json which is for JSON payloads.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps form field names to their values.

Flask
form_data = [1]: request.form[[2]] for [1] in request.form}}
Drag options to blanks, or click blank then click option'
Afield
Bvalue
Ckey
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for the key and the loop variable.
Using a variable name that does not match the loop variable.
5fill in blank
hard

Fill all three blanks to safely get a form value with a default fallback.

Flask
username = request.form.get([1], [2]) if request.method == [3] else None
Drag options to blanks, or click blank then click option'
A'username'
B'guest'
C'POST'
D'GET'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong HTTP method string in the condition.
Not providing a default value in get(), which can cause errors.