djangoajaxfirebase-realtime-databasereal-time-updatesreal-time-data

How to get updating values from python to template without refresh? Django


I have a real time database(google firebase), and its data is constantly changing, I want to display this data on my template without reloading the template itself. I couldn't find any related information, also I am sort of a beginner especially to AJAX so if you can provide an example or a documentation that would be really helpful.

Any help is appreciated


Solution

  • This have to be done by AJAX so the easiest way is to do the following

    1. take the part of the template that renders the data in a new template file
    2. include the new template in your main template
    3. write a new view e.g. pull_db_updates the pulls the data from Firebase and renders the new small template
    4. add view to urls.py
    5. in your main page, add a JS to update the page setInterval('update',5000) the update function shall call the new view using $.ajax and replace the div of the old data with new data.

    This is the polling method, there is the websocket method where the server notifies the client (browser) when there is a change.