R
R
Radren2016-09-12 19:55:08
Django
Radren, 2016-09-12 19:55:08

How to asynchronously pass the value of a variable from view to template?

Django.
There is a view (view1) in which the application can be considered anything for a long time, there is a calculation_progress variable. Requires the updated progress variable to be passed asynchronously to the browser.
I wrote a new view (view2) for this, so that it can be accessed from the browser with ajax for progress. But it's not clear how to take the progress variable updated in view1 from view2?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nirvimel, 2016-09-12
@nirvimel

Theoretical side:
There is one (suitable) technology for transferring events from the server to the client - this is WebSocket.
And there are a bunch of old crutches that were relevant before the advent of WebSocket - these are Commet , Long Polling , Server Push , and other techniques based on a mockery of the HTTP protocol that was not intended for this.
Look towards Django Channels .
For heavy computations and any (potentially) long running processes, asynchronous background task queues are supposed to be used:

  1. Celery is the most popular solution, practically the industry standard.
  2. Django Q is a young, fast growing competitor to Celery.
  3. huey, a little task queue is a much more lightweight option for simple applications.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question