Challenge - 5 Problems
Session Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when SESSION_COOKIE_AGE is set to 0?
In Django settings, if you set
SESSION_COOKIE_AGE = 0, what will be the behavior of the session cookie in the browser?Attempts:
2 left
💡 Hint
Think about what a zero value means for cookie expiration in browsers.
✗ Incorrect
Setting SESSION_COOKIE_AGE = 0 makes the session cookie a browser-length cookie. This means it will expire when the user closes the browser, not immediately or never.
❓ state_output
intermediate2:00remaining
What is the session expiry time after calling set_expiry(300)?
Given a Django view where
request.session.set_expiry(300) is called, what is the session expiry behavior?Django
def my_view(request): request.session.set_expiry(300) return HttpResponse('Hello')
Attempts:
2 left
💡 Hint
Check Django docs on set_expiry with integer values.
✗ Incorrect
Calling set_expiry(300) sets the session to expire 300 seconds after the last request that modified the session.
📝 Syntax
advanced2:00remaining
Which code snippet correctly sets a session to expire at browser close?
Select the Django code snippet that correctly sets the session to expire when the browser closes.
Attempts:
2 left
💡 Hint
Remember the special meaning of 0 in set_expiry.
✗ Incorrect
Using set_expiry(None) sets the session to expire when the browser closes. Other values have different meanings or cause errors.
🔧 Debug
advanced2:00remaining
Why does session never expire despite set_expiry(10)?
A developer sets
request.session.set_expiry(10) in a Django view, but the session never expires after 10 seconds. What is the most likely cause?Attempts:
2 left
💡 Hint
Think about how SESSION_SAVE_EVERY_REQUEST affects session expiry.
✗ Incorrect
If SESSION_SAVE_EVERY_REQUEST = True, the expiry time resets on every request, so the session never expires as long as the user keeps interacting.
🧠 Conceptual
expert2:00remaining
What error occurs if you call set_expiry with a string other than 'session' or 'never'?
In Django, what happens if you call
request.session.set_expiry('invalid_string')?Attempts:
2 left
💡 Hint
Check Django source or docs on allowed string values for set_expiry.
✗ Incorrect
Django's set_expiry accepts only integers, None, or strings 'session' or 'never'. Any other string raises a ValueError.