views.py
from django.http import HttpResponse
from random import choice
def index(request):
x = choice([0, 1, 2])
if x == 0:
request.session['a'] = 1
elif x == 1:
request.session.flush()
return HttpResponse(request.session.session_key + ' ' + str(request.session.keys()) + ' ' + str(x), content_type='text/plain')
- session.clear() method doesn't change session key.
- The session key was changed when call the session.flush() method. (eg. logout())
- If session isn't used in request, session key was changed on every request.