0
0
Flaskframework~10 mins

Request context 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 import the Flask request object.

Flask
from flask import [1]
Drag options to blanks, or click blank then click option'
Arequest
Bresponse
Csession
Dredirect
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'response' instead of 'request'.
Forgetting to import 'request'.
2fill in blank
medium

Complete the code to get the value of the 'username' parameter from a GET request.

Flask
username = request.args.get([1])
Drag options to blanks, or click blank then click option'
A'password'
B'username'
C'email'
D'id'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong parameter name.
Using request.form instead of request.args for GET parameters.
3fill in blank
hard

Fix the error in accessing JSON data from a POST request.

Flask
data = request.[1]
Drag options to blanks, or click blank then click option'
Aargs
Bvalues
Cjson
Dform
Attempts:
3 left
💡 Hint
Common Mistakes
Using request.form to get JSON data.
Trying to access get_json() on request.args.
4fill in blank
hard

Fill both blanks to check if the request method is POST and get form data 'email'.

Flask
if request.method == '[1]':
    email = request.form.get('[2]')
Drag options to blanks, or click blank then click option'
APOST
BGET
Cusername
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 'GET' instead of 'POST'.
Using wrong form field name.
5fill in blank
hard

Fill all three blanks to create a Flask route that accepts POST requests and reads JSON 'name' from the request.

Flask
@app.route('/submit', methods=[[1]])
def submit():
    data = request.get_json()
    name = data.get([2])
    return f"Hello, [3]!"
Drag options to blanks, or click blank then click option'
A'POST'
B'name'
Cname
D'GET'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GET' instead of 'POST' in methods.
Using the string 'name' instead of the variable name in the return.