7👍
two approaches:
-
just update the database and wait until the next AJAX query. That means it should do the query periodically, you’ll have to balance between immediacy and server load. It helps a little if you can do a cheap query to just verify if there has been an update. Maybe make that check rely only on memcached instead of going to the DB
-
use comet. In short: the client does an AJAX query asking for the update. the server sees there’s no update, so it doesn’t answer. Instead, the connection is kept open for a long time. Eventually either the update comes and the server finally answers, or the client times out and kill the connection. In that case, the client should immediately reissue the query to keep waiting for the update.
9👍
2021 update: Use channels: https://channels.readthedocs.io/en/latest/
You have two choices
- Have the browser poll using setTimeout()
- Look into Comet — this is a technique for pushing data from the server to the browser.
Here’s an article on Comet in Django
0👍
You can also use The Websocket API https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.
- Django aggregate Count only True values
- Django annotate groupings by month
- How to remove an app from a django projects (and all its tables)
- Convert requests.models.Response to Django HttpResponse