Search code examples
ajaxdjangocountdown

How to implement countdown timer in django


I just need a general idea. I'm developing a sports application in django. This application needs to measure time and display it to the user. During countdown I also need to perform some "action" which might occur. This means call another view according to a type of action, mark this action and redirect back to original view with timer where the user now can see the change. I suppose I can't implement countdown on server-side(django). I have to do this with JavaScript, but... the countdown stops everytime user performs an action. Do I have to use AJAX for this? Is't there a better way to achieve this. Thanks


Solution

  • You would definitely need some javascript to do the countdown timer. Like this one - http://keith-wood.name/countdown.html

    Then any action that happens, you can do a basic ajax call to your django URL(view) to update any values in the db or anything else you need to do with the request.

    When the countdown stops, you can probably record some time-left value into django and then when you need to continue the timer you can again do an ajax call to some view which will return you the time to start the countdown from and you can reconstruct your countdown timer with the time left.