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>
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 !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With