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 'Request' 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 create a Flask app instance.
Flask
app = [1](__name__) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'request' instead of 'Flask'.
Forgetting to pass __name__ as argument.
✗ Incorrect
We create the Flask app by calling Flask with the current module name.
3fill in blank
hardFix the error in the route decorator to handle POST requests.
Flask
@app.route('/login', methods=[[1]])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GET' which is for fetching data, not submitting.
Using 'PUT' or 'DELETE' which are not typical for forms.
✗ Incorrect
The login form should accept POST requests to submit data securely.
4fill in blank
hardFill both blanks to get the username from the form and check if it matches 'admin'.
Flask
username = request.form.get([1]) if username == [2]:
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'password' instead of 'username' to get the form data.
Comparing username to 'user' instead of 'admin'.
✗ Incorrect
We get the 'username' field from the form and compare it to the string 'admin'.
5fill in blank
hardFill all three blanks to return a welcome message with the username if login is successful.
Flask
if username == 'admin' and password == 'secret': return f"Welcome, [1]!" else: return [2]('login.html', [3]=True)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using redirect instead of render_template for failed login.
Not passing the error flag to the template.
✗ Incorrect
We show a welcome message with the username, and if login fails, render the login page with an error flag.