semvec/pypi-packages huggingface dataset:
django-session-timeout-2025 0.1.1
Middleware to expire sessions after specific amount of time
License: MIT


# django-session-timeout-2025

Add timestamp to sessions to expire them independently

## Installation

```shell
pip install django-session-timeout-2025
```

## 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/'
```