I have some problem related to that I am trying to implement a middleware which detects the whether the authenticated user is inactive for 5 seconds. I have wrote below Python module to do this job but It seems it is not works well. I found two reason ; One of them is ; I can not redirect the user to the home page correctly ; Middleware is not change session key correctly
I have not found that how I can solve this problems. I will show what I have done to the below as two part.
First part ; middleware.py
class TimeOut: @csrf_exempt def process_request(self, request): try : if request.session['isA'] == False: return #redirect(reverse("homePage_view")) except KeyError: request.session['isA'] = False return try : passT = datetime.now() - request.session['Time'] if passT > timedelta( 0, settings.SESSION_COOKIE, 0): request.session['isA'] = False del request.session['Time'] return except KeyError: pass request.session['Time'] = datetime.now()
Second part ; settings.py
SESSION_COOKIE = 5 MIDDLEWARE_CLASSES = ( 'home.middleware.TimeOut', )
EDIT: I have mistakenly wrote other class. I have changed the name as TimeOut