Challenge - 5 Problems
Session Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1:30remaining
What is the default session engine in Django?
Django supports multiple session engines. Which one is used by default if you do not change any settings?
Attempts:
2 left
💡 Hint
Think about where Django stores session data by default.
✗ Incorrect
The default session engine stores session data in the database using the django.contrib.sessions.backends.db backend.
❓ component_behavior
intermediate1:30remaining
What happens if 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?Attempts:
2 left
💡 Hint
Think about what a zero age means for cookies.
✗ Incorrect
Setting SESSION_COOKIE_AGE to 0 makes the session cookie a browser-length cookie, which expires when the browser closes.
📝 Syntax
advanced2:00remaining
Identify the correct way to configure a cache-based session engine
Which of the following settings correctly configures Django to use the cache session engine?
Attempts:
2 left
💡 Hint
Check the exact module path for the cache session backend.
✗ Incorrect
The correct setting for cache-based sessions is django.contrib.sessions.backends.cache.
🔧 Debug
advanced2:00remaining
Why does session data not persist across requests?
A developer sets
SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies' but notices session data is lost after each request. What is the most likely cause?Attempts:
2 left
💡 Hint
Signed cookies require a secret to sign the data.
✗ Incorrect
Signed cookie sessions require a properly set SECRET_KEY to sign and verify session data. Without it, session data cannot persist.
❓ state_output
expert2:00remaining
What is the output of this Django session code snippet?
Consider this Django view code snippet:
If a user visits this view 3 times in the same browser session, what will be the output on the third visit?
def view(request):
request.session['count'] = request.session.get('count', 0) + 1
return HttpResponse(str(request.session['count']))If a user visits this view 3 times in the same browser session, what will be the output on the third visit?
Django
def view(request): request.session['count'] = request.session.get('count', 0) + 1 return HttpResponse(str(request.session['count']))
Attempts:
2 left
💡 Hint
The session stores the count and increments it each visit.
✗ Incorrect
Each visit increments the 'count' in the session by 1. On the third visit, the count will be 3.