Recall & Review
beginner
What is the main purpose of the Flask-Login extension?
Flask-Login helps manage user sessions in Flask apps. It keeps track of logged-in users and handles login, logout, and session protection easily.
Click to reveal answer
beginner
Which function in Flask-Login is used to log a user in?
The
login_user() function logs a user in by creating a session for them.Click to reveal answer
beginner
What does the
@login_required decorator do?It protects routes so only logged-in users can access them. If a user is not logged in, it redirects them to the login page.
Click to reveal answer
intermediate
How does Flask-Login identify the current user in a request?
Flask-Login provides a
current_user proxy that represents the logged-in user or an anonymous user if no one is logged in.Click to reveal answer
intermediate
What must a user class implement to work with Flask-Login?The user class must have these methods: <code>is_authenticated</code>, <code>is_active</code>, <code>is_anonymous</code>, and a method <code>get_id()</code> that returns a unique ID as a string.Click to reveal answer
Which Flask-Login function logs out the current user?
✗ Incorrect
The
logout_user() function ends the user session and logs the user out.What does the
user_loader callback do in Flask-Login?✗ Incorrect
The
user_loader callback tells Flask-Login how to get a user object from a user ID stored in the session.What happens if a non-logged-in user tries to access a route with
@login_required?✗ Incorrect
The
@login_required decorator redirects users who are not logged in to the login page.Which attribute tells if a user is logged in or not?
✗ Incorrect
is_authenticated is True if the user is logged in, False otherwise.What type of value should
get_id() return?✗ Incorrect
get_id() must return a unique string that identifies the user for session management.Explain how Flask-Login manages user sessions in a Flask app.
Think about how users log in, stay logged in, and how routes can be protected.
You got /5 concepts.
Describe the requirements for a user class to work with Flask-Login.
Focus on the methods Flask-Login expects to check user status and identity.
You got /4 concepts.