Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Flask class.
Flask
from flask import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing render_template instead of Flask
Using lowercase flask instead of Flask
✗ Incorrect
The Flask class is imported from the flask module to create the app.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong field name
Forgetting to use request.form.get()
✗ Incorrect
The form field named 'name' is accessed using request.form.get('name').
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST
Using unsupported HTTP methods
✗ Incorrect
The POST method is required to handle form submissions securely.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for GET instead of POST
Using wrong form field names
✗ Incorrect
Check if the method is 'POST' and then get the 'email' field from the form.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST
Getting wrong form field
Using render_template instead of redirect
✗ Incorrect
The route accepts POST requests, gets the 'username' from the form, and redirects to '/dashboard'.