Reputation: 5188
I am new to Django and have completed the 7 part tutorial and am now trying to learn more by making my own app.
Suppose you are making an interactive data visualization application where the front end is powered by d3 (or your favorite JS library) and your data is coming from the server. Since your data is large, you first have to load it into server memory (maybe from a binary file, or however you store it). Yet you don't want your user to be looking at a blank page when they could be seeing the rest of the site (maybe filling in some parameters for the interactive data).
How can you, when a user requests a web-page, load and maintain data in memory on the server while Django still renders the page as well as maybe sends POST requests to update some server side information?
Upvotes: 1
Views: 2257
Reputation: 8506
Django doesn't have any asynchronous method to deal with what you're asking. The platform is request-based so there's no way to send the information later using the same request.
The solution in this case is using two views (or a view that can handle multiple formats, like @SumNeuron mentioned):
The first view loads the page where you'll be loading the data later. On that page, an XMLHttpRequest is done to request the data.
This view only sends the data, it can be just the data in JSON or it can be partial HTML made from a template.
Upvotes: 4