Skip to main content

Auto logout a user after specific time in Django

Project description

https://app.travis-ci.com/bugov/django-auto-logout.svg?branch=master

Auto logout a user after specific time in Django.

Works with Python🐍 ≥ 3.7, Django🌐 ≥ 3.0.

вњ”пёЏ Installation

pip install django-auto-logout

Append to settings middlewares:

MIDDLEWARE = [
...
    'django_auto_logout.middleware.auto_logout',
]

рџ’¤ Logout in case of idle

Logout a user if there are no requests for a long time.

Add to settings:

AUTO_LOGOUT = {'IDLE_TIME': 600}  # logout after 10 minutes of downtime

вЊ› Limit session time

Logout a user after 3600 seconds (hour) from the last login.

Add to settings:

AUTO_LOGOUT = {'SESSION_TIME': 3600}

вњ‰пёЏ Show messages when logging out automatically

Set the message that will be displayed after the user automatically logs out of the system:

AUTO_LOGOUT = {
    'SESSION_TIME': 3600,
    'MESSAGE': 'The session has expired. Please login again to continue.',
}

It uses django.contrib.messages. Don’t forget to display messages in templates:

{% for message in messages %}
    <div class="message {{ message.tags }}">
        {{ message }}
    </div>
{% endfor %}

рџЊ€ Combine configurations

You can combine previous configurations. For example, you may want to logout a user in case of downtime (5 minutes or more) and not allow working within one session for more than half an hour:

AUTO_LOGOUT = {
    'IDLE_TIME': 300,  # 5 minutes
    'SESSION_TIME': 1800,  # 30 minutes
    'MESSAGE': 'The session has expired. Please login again to continue.',
}

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-auto-logout-0.3.1.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file django-auto-logout-0.3.1.tar.gz.

File metadata

  • Download URL: django-auto-logout-0.3.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for django-auto-logout-0.3.1.tar.gz
Algorithm Hash digest
SHA256 b3689bc71cac4c8c26ac92fa94540a1cdc6c4adaac76a861a2162ed4cf4cc859
MD5 1098a56615f187d12df243aa8d4d414b
BLAKE2b-256 894233d0016ac6984cc4897d8160d6b99835980d72e5d0db0f73cb2975022f35

See more details on using hashes here.

Supported by

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