Complete the code to import the session object from Flask.
from flask import Flask, [1]
request instead of session.session.The session object is imported from Flask to store user session data.
Complete the code to set a secret key needed for session management.
app = Flask(__name__)
app.secret_key = [1]The secret key must be a string used to encrypt session data.
Fix the error in the code to store a username in the session.
from flask import Flask, session app = Flask(__name__) app.secret_key = 'key' @app.route('/login') def login(): session[1]['username'] = 'Alice' return 'Logged in'
session.set which is invalid.session.add which does not exist.Session acts like a dictionary, so use square brackets to set a key.
Fill both blanks to check if 'username' is in session and retrieve it safely.
from flask import session if [1] in session: user = session.[2]('username') else: user = 'Guest'
username instead of string 'username'.pop which removes the key instead of just getting it.Check if the string key 'username' is in session, then use get to retrieve it safely.
Fill all three blanks to clear the session and redirect to home page.
from flask import session, redirect, url_for @app.route('/logout') def logout(): session.[1]() return [2]( [3]('home') )
pop without a key to clear session.redirect or url_for.Use clear() to empty session, then redirect to the URL generated by url_for.
