Skip to main content

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.

Installation

  1. Run pip install django-session-refresh
  2. Add session_refresh.middleware.SessionRefreshMiddleware settings.py ass bellow
MIDDLEWARE = [
    ...
    'django.contrib.sessions.middleware.SessionMiddleware',  # Django default SessionMiddleware
    'session_refresh.middleware.SessionRefreshMiddleware',   # django-session-refresh
    ...
]

Configuration (optional)

The settings bellow are optional and if not defined in settings.py the default values will be used.

# The interval in seconds to refresh the session
SESSION_REFRESH_INTERVAL = 86400  # 24 hours
# The name of the session key to store the last refresh timestamp
SESSION_REFRESH_KEY = 'last_session_refresh'
# Skips session refresh for is_staff users
SESSION_REFRESH_SKIP_STAFF_USERS = False
# Skips session refresh for is_superuser users
SESSION_REFRESH_SKIP_SUPERUSER_USERS = True
# Skips session refresh for static and media file requests
SESSION_REFRESH_SKIP_STATIC_AND_MEDIA = True
# Skips session refresh for unauthenticated users
SESSION_REFRESH_SKIP_UNAUTHENTICATED_USERS = True

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_session_refresh-0.2.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_session_refresh-0.2.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file django_session_refresh-0.2.0.tar.gz.

File metadata

  • Download URL: django_session_refresh-0.2.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_session_refresh-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9c9ad31508daf1792fdee2a42dc521968f096b80806a83efafff4e643ce6d898
MD5 5d3c9d863fd13f280672fe1367792ab4
BLAKE2b-256 75f797dced957aa81b3c56da52be33a239b1445c5824e8bf05b68d47ae877c1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_session_refresh-0.2.0.tar.gz:

Publisher: publish.yml on amilnosredna/django-session-refresh

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_session_refresh-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_session_refresh-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 648453072d1206951e38776faa4db6ce5a779cecbe8c8b34de195333046ac585
MD5 829b7cdb406211ac17f51f396c9e2649
BLAKE2b-256 6052aff12003158ce42715f7bfbfc0533825a3b2a98acecfc78ac243c923559d

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_session_refresh-0.2.0-py3-none-any.whl:

Publisher: publish.yml on amilnosredna/django-session-refresh

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page