0
0
Flaskframework~10 mins

Why form handling matters in Flask - Test Your Understanding

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

Complete the code to import the Flask class.

Flask
from flask import [1]
Drag options to blanks, or click blank then click option'
AFlask
Brender_template
Crequest
Dredirect
Attempts:
3 left
💡 Hint
Common Mistakes
Importing render_template instead of Flask
Using lowercase flask instead of Flask
2fill in blank
medium

Complete the code to get form data from a POST request.

Flask
from flask import request

name = request.form.get('[1]')
Drag options to blanks, or click blank then click option'
Ausername
Bemail
Cname
Dpassword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong field name
Forgetting to use request.form.get()
3fill in blank
hard

Fix the error in the route decorator to accept POST requests.

Flask
@app.route('/submit', methods=[[1]])
Drag options to blanks, or click blank then click option'
A'GET'
B'PUT'
C'DELETE'
D'POST'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST
Using unsupported HTTP methods
4fill in blank
hard

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

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

Fill all three blanks to create a route that handles POST, gets username, and redirects.

Flask
@app.route('/login', methods=[[1]])
def login():
    if request.method == 'POST':
        user = request.form.get([2])
        return [3]('/dashboard')
Drag options to blanks, or click blank then click option'
A'POST'
B'username'
Credirect
Drender_template
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST
Getting wrong form field
Using render_template instead of redirect