https://github.com/labd/django-session-timeout
Add timestamp to sessions to expire them
https://github.com/labd/django-session-timeout
Last synced: 10 months ago
JSON representation
Add timestamp to sessions to expire them
- Host: GitHub
- URL: https://github.com/labd/django-session-timeout
- Owner: labd
- License: mit
- Created: 2017-08-31T19:21:05.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-05-09T17:19:49.000Z (about 4 years ago)
- Last Synced: 2025-06-29T03:44:16.613Z (12 months ago)
- Language: Python
- Size: 37.1 KB
- Stars: 39
- Watchers: 7
- Forks: 23
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES
- License: LICENSE
Awesome Lists containing this project
README
[](https://codecov.io/gh/labd/django-session-timeout)
[](https://pypi.python.org/pypi/django-session-timeout/)
[](https://django-session-timeout.readthedocs.io/en/latest/)
[](https://github.com/labd/django-session-timeout/actions)
# django-session-timeout
Add timestamp to sessions to expire them independently
## Installation
```shell
pip install django-session-timeout
```
## Usage
Update your settings to add the SessionTimeoutMiddleware:
```python
MIDDLEWARE_CLASSES = [
# ...
'django.contrib.sessions.middleware.SessionMiddleware',
'django_session_timeout.middleware.SessionTimeoutMiddleware',
# ...
]
```
And also add the ``SESSION_EXPIRE_SECONDS``:
```python
SESSION_EXPIRE_SECONDS = 3600 # 1 hour
```
By default, the session will expire X seconds after the start of the session.
To expire the session X seconds after the `last activity`, use the following setting:
```python
SESSION_EXPIRE_AFTER_LAST_ACTIVITY = True
```
By default, `last activity` will be grouped per second.
To group by different period use the following setting:
```python
SESSION_EXPIRE_AFTER_LAST_ACTIVITY_GRACE_PERIOD = 60 # group by minute
```
To redirect to a custom URL define the following setting:
```python
SESSION_TIMEOUT_REDIRECT = 'your_redirect_url_here/'
```