2

In one of my views I have several steps and they use 5 or 7 minutes to finish totally, so I was wondering if there is a way to print the status of the view in the browser, like:

"Calculating models..." "Post processing models..." "Making DB..." "Cleaning old tables..."

Is there a way to do that?

Thanks!

Hedde van der Heide
  • 21,841
  • 13
  • 71
  • 100

1 Answers1

4

Such heavy duty should probably not be part of a django view. You might want to look into django celery for asynchronous task management.

However you can do something like that just fine by polling your server. The easy setup, use short polling (basically a javascript loop that triggers an ajax request to the server every i seconds, retrieving a status response* which you can use to show your user anything).

*You'll have to setup an url and function that calculates the status somehow or if you're using celery you can use it's asynchronous result

Hedde van der Heide
  • 21,841
  • 13
  • 71
  • 100
  • Could you please make a complete example for those of us who are just starting web-dev and are not familiar with polling / ajax? see https://stackoverflow.com/questions/44537647/django-post-form-with-status-view-ajax/44538429?noredirect=1#comment76069033_44538429 – SumNeuron Jun 14 '17 at 08:37