Complete the code to import the Flask session object.
from flask import Flask, [1]
The session object is imported from Flask to manage user state across requests.
Complete the code to set a value in the session dictionary.
session[[1]] = 'user123'
We store the user's name under the key 'username' in the session to remember who is logged in.
Fix the error in the code to retrieve the username from the session safely.
user = session.get([1], None)
None to be returned.get and risking a KeyError.The key 'username' matches what was stored in the session, so we retrieve it safely with get.
Fill both blanks to check if a user is logged in and redirect if not.
if [1] not in session: return [2]('/login')
render_template instead of redirect.We check if 'username' is in session to know if the user is logged in. If not, we redirect to the login page.
Fill all three blanks to clear the session and log the user out.
from flask import [1] @app.route('/logout') def logout(): [2].clear() return [3]('/login')
session.request instead of session.We import session to clear all stored user data, then use redirect to send the user to the login page.