Complete the code to set a secret key for Flask sessions.
app = Flask(__name__)
app.secret_key = [1]The secret key must be a string used to sign session cookies securely.
Complete the code to store a username in the session after login.
from flask import session def login(): session[[1]] = 'user123'
Storing the username in session under the key 'username' helps identify the logged-in user.
Fix the error in the code to clear the session on logout.
from flask import session def logout(): [1].clear()
To clear all session data, call clear() on the session object.
Fill both blanks to check if a user is logged in by verifying the session key.
from flask import session def is_logged_in(): return [1] in session and session[[2]] is not None
Checking if 'username' exists and is not None in session confirms login status.
Fill all three blanks to create a secure session cookie with HttpOnly and Secure flags.
app.config['SESSION_COOKIE_HTTPONLY'] = [1] app.config['SESSION_COOKIE_SECURE'] = [2] app.config['SESSION_COOKIE_SAMESITE'] = [3]
Setting HttpOnly and Secure to True helps protect cookies. 'Lax' for SameSite balances security and usability.