0
0
Djangoframework~20 mins

Session framework configuration in Django - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Session Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1: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?
Adjango.contrib.sessions.backends.signed_cookies
Bdjango.contrib.sessions.backends.db
Cdjango.contrib.sessions.backends.file
Ddjango.contrib.sessions.backends.cache
Attempts:
2 left
💡 Hint
Think about where Django stores session data by default.
component_behavior
intermediate
1: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?
AThe session cookie will expire immediately and not be saved.
BThe session cookie will last for the default 2 weeks.
CThe session cookie will never expire.
DThe session cookie will expire when the browser is closed.
Attempts:
2 left
💡 Hint
Think about what a zero age means for cookies.
📝 Syntax
advanced
2: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?
ASESSION_ENGINE = 'django.contrib.sessions.backends.cache'
BSESSION_ENGINE = 'django.contrib.sessions.cache_backend'
CSESSION_ENGINE = 'django.sessions.backends.cache'
DSESSION_ENGINE = 'django.contrib.cache.sessions'
Attempts:
2 left
💡 Hint
Check the exact module path for the cache session backend.
🔧 Debug
advanced
2: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?
AThe SECRET_KEY setting is missing or not set properly.
BThe database migrations for sessions were not run.
CThe cache backend is not configured.
DThe SESSION_COOKIE_AGE is set too high.
Attempts:
2 left
💡 Hint
Signed cookies require a secret to sign the data.
state_output
expert
2:00remaining
What is the output of this Django session code snippet?
Consider this Django view code snippet:
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']))
A1
B2
C3
DError: 'count' key not found
Attempts:
2 left
💡 Hint
The session stores the count and increments it each visit.