This is the code from my Django and Socket.IO realtime tutorial which you can find at http://maxburstein.com/blog/realtime-django-using-nodejs-and-socketio/