[Answer]-Persist session data Django

1👍

Django sessions are persisted to the db by default.

Read the docs:
https://docs.djangoproject.com/en/dev/topics/http/sessions/#configuring-the-session-engine
https://docs.djangoproject.com/en/dev/topics/http/sessions/#when-sessions-are-saved
https://docs.djangoproject.com/en/dev/topics/http/sessions/#clearing-the-session-store

Update:

The only situation where Django ‘knows’ the session has expired is when the user logs out manually. In this case you could connect to the user_logged_out signal to do your data migration.

Otherwise the old session data stays in the db. Django provides the clearsessions management command to delete old sessions. They suggest you run it daily on the crontab.

You could write your own version of that command which also does your data migration.

Leave a comment