0
0
Flaskframework~10 mins

Accessing form data in routes 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'
A'username'
Busername
C'user'
Dform['username']
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the field name without quotes causes a NameError.
Using dictionary access like form['username'] inside get() is incorrect.
2fill in blank
medium

Complete the code to import the Flask request object.

Flask
from flask import [1]
Drag options to blanks, or click blank then click option'
Aredirect
BFlask
Crender_template
Drequest
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Flask instead of request.
Importing unrelated functions like render_template or redirect.
3fill in blank
hard

Fix the error in the route to correctly access form data for 'email'.

Flask
@app.route('/submit', methods=['POST'])
def submit():
    email = request.[1]['email']
    return f"Email: {email}"
Drag options to blanks, or click blank then click option'
Aform
Bform.get
Cform.get()
Dform.get('email')
Attempts:
3 left
💡 Hint
Common Mistakes
Using form.get() with parentheses after form causes an error.
Trying to call get as an attribute incorrectly.
4fill in blank
hard

Fill both blanks to create a route that handles POST requests and retrieves 'password' from form data.

Flask
@app.route('/login', methods=[[1]])
def login():
    password = request.form.get([2])
    return f"Password: {password}"
Drag options to blanks, or click blank then click option'
A'POST'
B'GET'
C'password'
D'userpass'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GET' instead of 'POST' in methods.
Passing the wrong string or variable name to get() for the password.
5fill in blank
hard

Fill all three blanks to create a route that accepts POST, retrieves 'email' and 'name' from form data, and returns a greeting.

Flask
@app.route('/greet', methods=[[1]])
def greet():
    email = request.form.get([2])
    name = request.form.get([3])
    return f"Hello, {name}! Your email is {email}."
Drag options to blanks, or click blank then click option'
A'POST'
B'email'
C'name'
D'username'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GET' instead of 'POST' in methods.
Mixing up form field names or using incorrect strings.