0
0
Flaskframework~5 mins

Flask-Login extension - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Alogout_user()
Blogin_user()
Ccurrent_user()
Duser_loader()
What does the user_loader callback do in Flask-Login?
ALoads a user from the database by ID
BLogs a user in
CLogs a user out
DProtects routes
What happens if a non-logged-in user tries to access a route with @login_required?
AThey get a 404 error
BThey see the page anyway
CThe app crashes
DThey are redirected to the login page
Which attribute tells if a user is logged in or not?
Acurrent_user.is_active
Bcurrent_user.is_authenticated
Ccurrent_user.get_id()
Dcurrent_user.is_anonymous
What type of value should get_id() return?
AA list of permissions
BA boolean
CA unique string identifying the user
DAn integer count
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.