Django Session timer Countdown

Asked

Viewed 462 times

4

I have it on my login screen: SESSION_COOKIE_AGE = 1200 # 20 minutos and would like to show the remaining time on my template.

Someone knows a good middleware or package for Django that adds a time counter to finish the login session. I found nothing integrated with Django, only Javascript solutions.

  • The solution is to calculate the difference between the datetime that the login was made and this datetime + 20min, pick up the result and play to the template in form of seconds. With the Javascript you have just put the count from the remaining seconds.

  • Correction: (datetime from login + 20min) - datetime current

  • Hey Origon, this way I would have to manipulate the same data, the 20 minutes twice, in the session and in the view. I created a view for ajax request, which returns me the remaining time and with a Countdown in jquery I show it in the template. That way everything is synchronized. key = request.COOKIES['sessionid'] Session = Session.objects.get(session_key=key) remainder = Session.expire_date

  • 1

    I’d like to know your motivations for implementing this. Does the original issue relate to your users being actively using the system and losing access between requests because the session has expired? This is the standard behavior of SESSION_COOKIE_AGE, it imposes an end date even if your user is actively using the system. I usually implement a middeware that renews the expiration date with each new access, it is a different approach to treat the problem. If it makes sense to you, I can post a code snippet of this middleware as a response. Abs!

  • Good believe that to have a counter you will need jquery, socket.io to do the same if you want python solution of a read in Tornado or libs to Realtime in python.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.