Get a Session Variable
A snippet showing how to get session variables in Django.
# views.py
def get_session(request):
username = request.session.get('username', 'Guest')
return HttpResponse(f"Hello {username}")
Explanation:
-
Use
request.session.get('key', 'default')to get a session variable.
- Category Sessions & Cookies
- Total Views 965
- Last Modified 25 June, 2026
- Tags #sessions #get #request #django
Previous snippet
Set a Session Variable
Next snippet