X
X
Xcopy2015-05-18 11:29:41
Django
Xcopy, 2015-05-18 11:29:41

How to set session lifetime in Django?

In addition to the main login method (through forms with csrf verification), I make an additional view for logging in mobile devices.
Mobile devices will log in through a simple, login(request, user), and I will give the client a request.session.session_key (this is the session_id of the session).
The thing is that I would like to set the lifetime of this (namely this) session equal to, for example, five years.
Digging through the documentation, I found this setting:

SESSION_COOKIE_AGE - Session cookie age in seconds.
Default: 1209600 (2 weeks in seconds)

But I do not want to change the lifetime of all sessions, I need to somehow set the lifetime of this particular session.
How to do it?
Thanks in advance for your reply.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2015-05-18
@perminovma

from django.contrib.sessions.models import Session

Session.objects.get(session_key=request.session.session_key).expire_date

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question