In the view I have:
from datetime import timedelta
from django.utils import timezone
now = timezone.now()
self.request.session.set_expiry(now + timedelta(days=365))
but it raises
datetime.datetime(2016, 6, 24, 17, 19, 0, 826661, tzinfo=) is not JSON serializable
I've found one solution:
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
but it works only in Chrome ... in Safari django raises error
UnpicklingError at / invalid load key, '{'.
Any suggestions?
Workaround #1
self.request.session.set_expiry(int(timedelta(days=365).total_seconds()))
According to Django documentation:
So, you are getting the expected behavior. If you want to pass a datetime to session.set_expiry, you have to use PickleSerializer. In my opinion, the workaround you proposed, it's actually the best solution, and keep using the JSONSerializer.