Django - show loading message during long processing

前端 未结 7 1424
野的像风
野的像风 2020-12-03 03:54

How can I show a please wait loading message from a django view?

I have a Django view that takes significant time to perform calculations on a large dataset

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-03 04:18

    Here is another explanation on how to get a loading message for long loading Django views

    Views that do a lot of processing (e.g. complex queries with many objects, accessing 3rd party APIs) can take quite some time before the page is loaded and shown to the user in the browser. What happens is that all that processing is done on the server and Django is not able to serve the page before it is completed.

    The only way to show a show a loading message (e.g. a spinner gif) during the processing is to break up the current view into two views:

    1. First view renders the page with no processing and with the loading message

    2. The page includes a AJAX call to the 2nd view that does the actual processing. The result of the processing is displayed on the page once its done with AJAX / JavaScript

提交回复
热议问题