A simple Django middleware to refresh user sessions periodically to prevent timeout during active use
Project description
django-session-refresh
A simple Django middleware to refresh user sessions periodically (24h by default) to prevent timeout during user activity.
This middleware updates a timestamp in the session data at specified intervals, effectively extending the session's lifetime as long as the user is active.
- Since this middleware depends on user information, it should be placed after Django's
AuthenticationMiddlewarein the middleware stack.
Installation
- Run
pip install django-session-refresh - Add
django_session_refresh.middleware.SessionRefreshMiddlewaretosettings.pyass bellow
MIDDLEWARE = [
...
'django.contrib.auth.middleware.AuthenticationMiddleware', # Django default AuthenticationMiddleware
'django_session_refresh.middleware.SessionRefreshMiddleware', # django-session-refresh
...
]
Configuration (optional)
The dictionary settings bellow are optional and if not defined in settings.py the default values will be used.
DJANGO_SESSION_REFRESH = {
# The interval in seconds to refresh the session
'REFRESH_INTERVAL': 86400, # 24 hours in seconds
# The name of the session key to store the last refresh timestamp
'SESSION_KEY_NAME': 'django_session_refreshed_at',
# The name of the request attribute to store session refresh information
'REQUEST_ATTR_NAME': 'django_session_refresh',
# Skips session refresh for is_staff users
'SKIP_STAFF_USERS': False,
# Skips session refresh for is_superuser users
'SKIP_SUPERUSER_USERS': True,
# Skips session refresh for static and media file requests
'SKIP_STATIC_AND_MEDIA': True,
# Skips session refresh for unauthenticated users
'SKIP_UNAUTHENTICATED_USERS': True,
}
Request features
After a successful session refresh, the middleware adds the following dictionary attribute to the request object:
request.django_session_refresh['refreshed']: A boolean indicating whether the session was refreshed during the current request.request.django_session_refresh['refreshed_at']: A datetime object representing the timestamp when the session was last refreshed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_session_refresh-0.3.0.tar.gz.
File metadata
- Download URL: django_session_refresh-0.3.0.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89b6e0d2a765e71e1dfb1009f9c1aa37a23560bb817ee953a467684bdf953fb3
|
|
| MD5 |
560d0e4bd12ff3557c031206c635b8aa
|
|
| BLAKE2b-256 |
a3be65b705c59036aa53b2f8a719f7bafb72c62809335f42f24863c3c60a845e
|
Provenance
The following attestation bundles were made for django_session_refresh-0.3.0.tar.gz:
Publisher:
publish.yml on amilnosredna/django-session-refresh
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_session_refresh-0.3.0.tar.gz -
Subject digest:
89b6e0d2a765e71e1dfb1009f9c1aa37a23560bb817ee953a467684bdf953fb3 - Sigstore transparency entry: 1270645668
- Sigstore integration time:
-
Permalink:
amilnosredna/django-session-refresh@9703ea19c6c2a713ef8a7e5d0ed3da7afab049e9 -
Branch / Tag:
refs/tags/0.3.0 - Owner: https://github.com/amilnosredna
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9703ea19c6c2a713ef8a7e5d0ed3da7afab049e9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file django_session_refresh-0.3.0-py3-none-any.whl.
File metadata
- Download URL: django_session_refresh-0.3.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ddaa4a304a2430d54b6ab610259043aeafc08d0513fba18f53503dd8f6c2078
|
|
| MD5 |
b0151df1f0496af66f7ec44de631f838
|
|
| BLAKE2b-256 |
4bea3b07315f54fb702efb016f63615347fd1fb73be21869ea85251814b7b7d2
|
Provenance
The following attestation bundles were made for django_session_refresh-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on amilnosredna/django-session-refresh
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_session_refresh-0.3.0-py3-none-any.whl -
Subject digest:
9ddaa4a304a2430d54b6ab610259043aeafc08d0513fba18f53503dd8f6c2078 - Sigstore transparency entry: 1270645691
- Sigstore integration time:
-
Permalink:
amilnosredna/django-session-refresh@9703ea19c6c2a713ef8a7e5d0ed3da7afab049e9 -
Branch / Tag:
refs/tags/0.3.0 - Owner: https://github.com/amilnosredna
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9703ea19c6c2a713ef8a7e5d0ed3da7afab049e9 -
Trigger Event:
release
-
Statement type: