Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django web frame real time data

I am writing a Django project that display data from mysql database, database is constantly getting update, how can I constantly send data in view.py. I tried looking at many modules I came across celery,Tornado, Django channels but they are mostly written for chat applications, also I tried considering using Node.js with Django. But what is the real solution for a simple data update in Django ?

Right now I simply use this code in my html file that refresh the page and gets the last data but the problem is that it makes the website run very slow :

<script>

    var myVar = setInterval(ReLoad , 2000); //refresh every 2 seconds

    function ReLoad() {
        $("#live").load(document.URL + " #live");
    }

</script>
like image 417
sam Avatar asked Feb 12 '26 22:02

sam


1 Answers

You might want to look into ajax (asynchronous javascript). For something to update on the page you typically need to refresh the page. If only a part of the page needs to be refreshed in the background u can use ajax. You can look into google's angular js and facebook's React js libraries. They developed these so u could get a notification without refreshing. I Know u can integrate it into django easily (not quite sure how tho).

Hopefully this can give you some clues as to where to go from here !

like image 174
Max Smith Avatar answered Feb 14 '26 12:02

Max Smith