Access Session Keys and Values
A snippet showing how to loop through session data in Django.
# views.py
def session_keys(request):
data = [f"{key}: {value}" for key, value in request.session.items()]
return HttpResponse("
".join(data))
Explanation:
-
Use
request.session.items()to get all keys and values. - Displays all keys and values in the current session.
- Category Sessions & Cookies
- Total Views 871
- Last Modified 12 July, 2026
- Tags #sessions #access #keys #django
Previous snippet