Anthony Dito
Anthony Dito

Reputation: 3670

Django continually checking database for new information

So, I was running some ideas through my head for a new website to build, and I am going to need something that would continually checks for new information. I looked around the internet and didn't find any django packages that would help me out. What I would do right now is...

var timer = setInterval(function() {timerFunc()}, delay);
function timerFunc() {
    //ajax here to check for new stuff...
}

For some reason, I have this notion that it should be possible to have the server-side alert the client side if there is new information but I have no particular reason to believe that. So, my questions are if there is a better way to do this, and if the code I have written is bad practice?

Upvotes: 0

Views: 134

Answers (1)

vishen
vishen

Reputation: 469

What you are looking for is Websockets (http://en.wikipedia.org/wiki/WebSocket) I believe. They allow the server to send events to the client, instead of polling the server from the client (which is what you are suggesting here).

I may be wrong here, but it looks like there isn't many Django Websocket libraries out there, I have heard about https://github.com/jonashagstedt/swampdragon but have never used it.

I think (again I could be wrong here) that you may want to use another web framework if you want to use Websockets, I know Flask seems pretty compatible with them http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent.

Upvotes: 1

Related Questions