[Django]-How can i make a delay of 5 sec while redirecting one page to another in django views

5👍

You can use jquery settimeout function on the respective page, where you want stay for certain time say 5 sec.

For Example :

setTimeout(function() {
     $.get("{% url 'ABC' %}") // Do something after 5 seconds
}, 5000);

inside function you can put the code for redirect ‘ABC’ is the url name which you define in urls.py file

2👍

just import time module in your views file and call sleep method and
pass the time

from django.http import HttpResponseRedirect
import time

def myview(request) :
    time.sleep(5)
    return HttpResponseRedirect("/path/")

or you can just add this javascript snippets in your template file

 <script>
       setTimeout(function(){
            window.location.href = 'here pass the path';
         }, 5000);
   </script>

Leave a comment