1

I'm fairly new to Django and couldn't figure this one out. I have a HTML page with a form, and once the user clicks submit an external python script is called using celery. I have a view that can check if the celery job is done, but how do I continually poll the database to check if my job is done? Is there a way to "refresh" the view so that it continually polls the job status? I know you can do this in javascript, but I'm not sure how to integrate this with Django (is there some sort of module...)? Any help would be great, thanks!

kinsigne
  • 73
  • 2
  • 8
  • You should take a look to signals: https://docs.djangoproject.com/en/dev/topics/signals/ – David Dahan Jun 12 '14 at 00:01
  • 1
    @DavidW. how do Signals help? – yedpodtrzitko Jun 12 '14 at 00:04
  • "how do I continually poll the database to check if my job is done?" -> usually you don't, you send an event/signal/whatever when the job is done. However, if the whole purpose is to change display of a page without realoding it, Ajax is what you're looking for (cf. Matt answer) – David Dahan Jun 12 '14 at 00:11
  • What I'm going for is to have a simple view that displays with "Process is running..." and when the process is done, display a new HTML page. I wanted the view to continually check the job status, but maybe Ajax/Javascript is the way to go? – kinsigne Jun 12 '14 at 00:17

2 Answers2

3

You can redirect yourself to your own html (https://realpython.com/django-redirects/) On your view.py, after the 'POST' case:

return redirect(request.META['HTTP_REFERER'])
petacreepers23
  • 164
  • 1
  • 9
0

You're on the right track. What you're looking for is Javascript and Ajax. This is a good answer.

Community
  • 1
  • 1
Matt
  • 8,758
  • 4
  • 35
  • 64
  • Thanks, the post you gave is pretty detailed. Where would I place the Ajax call exactly? Within my Django view? – kinsigne Jun 12 '14 at 00:15
  • The Ajax call would be in your Javascript. The Django view is what will be responding to the Ajax call. – Matt Jun 12 '14 at 00:22