0
0
Flaskframework~10 mins

Login form and verification 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 class.

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

Complete the code to create a Flask app instance.

Flask
app = [1](__name__)
Drag options to blanks, or click blank then click option'
AFlask
Brender_template
Crequest
Dredirect
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'request' instead of 'Flask'.
Forgetting to pass __name__ as argument.
3fill in blank
hard

Fix 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'
A'PUT'
B'POST'
C'GET'
D'DELETE'
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.
4fill in blank
hard

Fill 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'
A'username'
B'password'
C'admin'
D'user'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'password' instead of 'username' to get the form data.
Comparing username to 'user' instead of 'admin'.
5fill in blank
hard

Fill 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'
Ausername
Brender_template
Cerror
Dredirect
Attempts:
3 left
💡 Hint
Common Mistakes
Using redirect instead of render_template for failed login.
Not passing the error flag to the template.