Last modified: Jan 10, 2023 By Alexander Williams

Setting the Expiration Time of the Session set_expiry()

In this article we will set the expiration time of the session

syntax:

1
set_expiry(value)

If value is an integer, the session will expire after that many seconds of inactivity. For example, calling request.session.set_expiry(300) would make the session expire in 5 minutes.

If value is a datetime or timedelta object, the session will expire at that specific date/time. Note that datetime and timedelta values are only serializable if you are using the PickleSerializer.

If value is 0, the user’s session cookie will expire when the user’s Web browser is closed.

If value is None, the session reverts to using the global session expiry policy.

example:

1
request.session.set_expiry(500) #this session will be expire after 5min