@@ -53,6 +53,56 @@ from datetime import timedelta
53
53
AUTO_LOGOUT = {' IDLE_TIME' : timedelta(minutes = 10 )}
54
54
```
55
55
56
+ The user will log out the next time the page is requested.
57
+ See ` REDIRECT_TO_LOGIN_PAGE ` to log out right after the idle-time has expired
58
+ (and redirect to login page).
59
+
60
+ ### 🔄 ` REDIRECT_TO_LOGIN_PAGE ` right after the idle-time has expired
61
+
62
+ Use the ` REDIRECT_TO_LOGIN_PAGE ` option
63
+ if you want to redirect the user to the login page
64
+ immediately after the idle-time expires:
65
+
66
+ ``` python
67
+ from datetime import timedelta
68
+
69
+ AUTO_LOGOUT = {
70
+ ' IDLE_TIME' : timedelta(minutes = 10 ),
71
+ ' REDIRECT_TO_LOGIN_PAGE' : True ,
72
+ }
73
+ ```
74
+
75
+ This requires a client-side script, so you should
76
+ modify your ` context_processors ` in ` settings.py ` :
77
+
78
+ ``` python
79
+ TEMPLATES = [
80
+ {
81
+ ' BACKEND' : ' django.template.backends.django.DjangoTemplates' ,
82
+ ' DIRS' : [],
83
+ ' APP_DIRS' : True ,
84
+ ' OPTIONS' : {
85
+ ' context_processors' : [
86
+ ' django.template.context_processors.debug' ,
87
+ ' django.template.context_processors.request' ,
88
+ ' django.contrib.auth.context_processors.auth' ,
89
+ ' django.contrib.messages.context_processors.messages' ,
90
+ # ↓↓↓ Add this ↓↓↓
91
+ ' django_auto_logout.context_processors.auto_logout_client' ,
92
+ ],
93
+ },
94
+ },
95
+ ]
96
+ ```
97
+
98
+ And add it to your templates (will add a redirect script to your html):
99
+
100
+ ```
101
+ {{ redirect_to_login_page }}
102
+ ```
103
+
104
+ It also works with ` SESSION_TIME ` .
105
+
56
106
## ⌛ Limit session time
57
107
58
108
Logout a user after 3600 seconds (hour) from the last login.
@@ -71,6 +121,16 @@ from datetime import timedelta
71
121
AUTO_LOGOUT = {' SESSION_TIME' : timedelta(hours = 1 )}
72
122
```
73
123
124
+ ---
125
+
126
+ ** NOTE**
127
+
128
+ See ` REDIRECT_TO_LOGIN_PAGE ` option
129
+ if you want to redirect user to the login page
130
+ right after the idle-time has expired.
131
+
132
+ ---
133
+
74
134
## ✉️ Show messages when logging out automatically
75
135
76
136
Set the message that will be displayed after the user automatically logs out of the system:
0 commit comments