Recall & Review
beginner
What is session expiry in Django?
Session expiry in Django means the time when a user's session data is deleted or becomes invalid, requiring the user to log in again or start a new session.
Click to reveal answer
beginner
How can you set a session to expire when the user closes the browser in Django?
Set SESSION_EXPIRE_AT_BROWSER_CLOSE = True in Django settings. This makes the session expire as soon as the browser is closed.
Click to reveal answer
beginner
What does the setting SESSION_COOKIE_AGE control in Django?
SESSION_COOKIE_AGE controls how long (in seconds) a session cookie lasts before it expires. The default is 1209600 seconds (2 weeks).
Click to reveal answer
intermediate
How can you programmatically set a custom expiry time for a session in Django?
Use request.session.set_expiry(value) where value can be seconds (int), a datetime or timedelta object, or 0 to expire on browser close.
Click to reveal answer
beginner
What happens if you do not set any session expiry in Django?
If no expiry is set, Django uses the default SESSION_COOKIE_AGE (2 weeks) and the session will expire after that time unless the user logs out or clears cookies.
Click to reveal answer
Which Django setting makes the session expire when the browser closes?
✗ Incorrect
Setting SESSION_EXPIRE_AT_BROWSER_CLOSE to True makes the session cookie expire when the browser closes.
What is the default duration of a Django session cookie if not changed?
✗ Incorrect
By default, SESSION_COOKIE_AGE is 1209600 seconds, which equals 2 weeks.
How do you set a session to expire after 5 minutes programmatically?
✗ Incorrect
Passing 300 seconds to set_expiry sets the session to expire after 5 minutes.
If SESSION_EXPIRE_AT_BROWSER_CLOSE is False and SESSION_COOKIE_AGE is 0, what happens?
✗ Incorrect
When SESSION_EXPIRE_AT_BROWSER_CLOSE is False and SESSION_COOKIE_AGE is 0, the session cookie is set with max_age=0, causing it to expire immediately.
Which method is used to clear session data in Django?
✗ Incorrect
request.session.clear() removes all session data but keeps the session active.
Explain how Django handles session expiry by default and how you can customize it.
Think about settings and methods that control session lifetime.
You got /4 concepts.
Describe how to make a Django session expire immediately when the user closes their browser.
Focus on the setting that links session expiry to browser behavior.
You got /3 concepts.