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.
Metadata
Release files for django-session-refresh 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_session_refresh-0.3.0.tar.gz | 7.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_session_refresh-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.2 kB
Release files / django_session_refresh-0.3.0.tar.gz
| Download URL | django_session_refresh-0.3.0.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
89b6e0d2a765e71e1dfb1009f9c1aa37a23560bb817ee953a467684bdf953fb3
|
|
BLAKE2b-256 checksum How to use checksums |
a3be65b705c59036aa53b2f8a719f7bafb72c62809335f42f24863c3c60a845e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 10, 2026.
Transparency logRelease files / django_session_refresh-0.3.0-py3-none-any.whl
| Download URL | django_session_refresh-0.3.0-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9ddaa4a304a2430d54b6ab610259043aeafc08d0513fba18f53503dd8f6c2078
|
|
BLAKE2b-256 checksum How to use checksums |
4bea3b07315f54fb702efb016f63615347fd1fb73be21869ea85251814b7b7d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 10, 2026.
Transparency log