Refresh a page when something new appears in Django

I'm creating a website for a local establishment that uses Ifood. Ifood provides an API that allows you to check information, both regarding establishments and incoming orders. The code is ready, but I can only show a new order update when manually refreshing the page. Which is a bit shippable. I thought about putting an automatic update with JavaScript at the given time, but it would be an ugly workaround. In this case, I'm getting JSON data, but in a more general context. How could I refresh the page as soon as new data appears?

An automatic update with Javascript might not be as dirty as you think. Even smartphone push notifications are really just occasionally polling under the hood.

If you really want to push from your server, WebSockets or server-side events are what you want. Unfortunately, it seems this kind of setup is not natively supported by Django.

Another option could be to use a paid service like Pusher.com. Such services usually let you listen for an even in JS, then call an API endpoint to trigger it from your server.

Back to Top