In my settings.py I state this and the sessionId did expire but it redirect me to some random links that I never state at all instead back to the login page and will show some error, I want it to redirect back to the login page after 10 seconds of inactivity, how do I do that?
My settings.py
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django_session_timeout.middleware.SessionTimeoutMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
SESSION_EXPIRE_SECONDS = 10
SESSION_EXPIRE_AFTER_LAST_ACTIVITY = True
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
My views.py
def login_view(request):
form = LoginForm(request.POST or None)
msg = None
if request.method == 'POST':
if form.is_valid():
username = form.cleaned_data.get('username') # retrieve the username
password = form.cleaned_data.get('password') # retrieve the password
user = authenticate(username=username, password=password) # authenticate user
if user is not None and user.is_admin: # authenticated if user is an admin
login(request, user)
return redirect('adminpage') # redirect the user to the admin page
elif user is not None and user.is_customer: # authenticated if user is a customer service
login(request, user)
return redirect('customer') # redirect the user to the customer service page
elif user is not None and user.is_logistic: # # authenticated if user is a logistic
login(request, user)
return redirect('logistic') # redirect the user to the logistic page
else:
msg = 'invalid credentials'
else:
msg = 'error validating form'
return render(request, 'login.html', {'form': form, 'msg': msg})
def admin(request):
return render(request, 'admin.html')
My urls.py
urlpatterns = [
path('', views.index, name='index'),
path('login/', views.login_view, name='login_view'),
path('register/', views.register, name='register'),
path('adminpage/', views.admin, name='adminpage'),
path('customer/', views.customer, name='customer'),
path('logistic/', views.logistic, name='logistic'),
path('forget/', views.forget, name='forget'),
path('newblock/', views.newblock, name='newblock'),
path('quote/', views.quote, name='quote'),
path('profile/', views.profile, name='profile'),
path('adminprofile/', views.adminprofile, name='adminprofile'),
]
This is the error message it show me after the session expire:
