Complete the code to import the Flask login manager.
from flask_login import [1]
The LoginManager class is imported from flask_login to manage user sessions and protect routes.
Complete the code to protect the admin route so only logged-in users can access it.
@app.route('/admin') @[1] def admin_panel(): return 'Welcome to admin panel'
login_manager.login_view which is a configuration, not a decorator.current_user.is_authenticated without a decorator.The @login_required decorator ensures that only logged-in users can access the /admin route.
Fix the error in the user loader function to load a user by ID.
@login_manager.user_loader def load_user([1]): return User.query.get(int(user_id))
user_id causes errors.current_user as a parameter.The user loader function must accept user_id as the parameter to load the user correctly.
Fill both blanks to check if the current user is authenticated and has admin role.
if current_user.[1] and current_user.[2] == 'admin': return 'Access granted' else: return 'Access denied'
username instead of role to check admin rights.is_active instead of is_authenticated.Check is_authenticated to confirm login and role to verify admin rights.
Fill all three blanks to create a dictionary comprehension that maps usernames to emails for users with admin role.
admin_users = {user.[1]: user.[2] for user in users if user.[3] == 'admin'}id instead of username as dictionary keys.email instead of role.This comprehension creates a dictionary with usernames as keys and emails as values, filtering only users with the admin role.