diff --git a/README.md b/README.md index 5f9970d..19f5892 100644 --- a/README.md +++ b/README.md @@ -48,3 +48,10 @@ 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_CUSTOM_REDIRECT = 'your_redirect_url_here/' +``` +...note the trailing slash. \ No newline at end of file diff --git a/src/django_session_timeout/middleware.py b/src/django_session_timeout/middleware.py index d6a9e41..e0b7468 100644 --- a/src/django_session_timeout/middleware.py +++ b/src/django_session_timeout/middleware.py @@ -2,6 +2,7 @@ from django.conf import settings from django.contrib.auth.views import redirect_to_login +from django.shortcuts import redirect try: from django.utils.deprecation import MiddlewareMixin @@ -27,7 +28,10 @@ def process_request(self, request): if session_is_expired: request.session.flush() - return redirect_to_login(next=request.path) + if settings.SESSION_TIMEOUT_CUSTOM_REDIRECT is not None: + return redirect(settings.SESSION_TIMEOUT_CUSTOM_REDIRECT) + else: + return redirect_to_login(next=request.path) expire_since_last_activity = getattr( settings, "SESSION_EXPIRE_AFTER_LAST_ACTIVITY", False