Complete the code to set a session variable in Django.
request.session[[1]] = 'user123'
Session keys must be strings, so quotes are needed around 'user_id'.
Complete the code to set the session expiry time to 5 minutes.
request.session.set_expiry([1])The set_expiry method expects seconds, so 5 minutes is 300 seconds.
Fix the error in the code to clear the session data properly.
request.session.[1]()The flush() method clears the session data and deletes the session cookie.
Fill both blanks to check if the session has expired and then set a new expiry.
if request.session.get_expiry_age() [1] 0: request.session.set_expiry([2])
Check if expiry age is less than 0 (expired), then set expiry to 300 seconds (5 minutes).
Fill all three blanks to create a session dictionary comprehension that stores user IDs with expiry times greater than 10 minutes.
active_sessions = {user: request.session.get_expiry_age() [1] 600 for user in users if request.session.get_expiry_age() [2] 600 and request.session.exists([3])}The comprehension filters users with expiry age greater than 600 seconds (10 minutes) and checks if the session exists for that user key.