Why do we want to make real time websites? Better user experience. More options on the front end. It makes the web feel more like native apps. You can show live data! Collaboration is much easier.
When you want to make it with django, you need to find the right tool. Django itself as such is not really suited. There are some criteria:
Some good socket-or-whatever-alternative-you-need implementation.
You need good browser support (also old IE versions).
It should be usable from python, it doesn’t need to be written in python per se.
You should not have to do a full-scale rebuild of an existing front-end.
You need to communicate between python and node.js. Redis works fine for cross-language communication. Redis supports many datatypes, so that’s fine.
The basic setup: Django or celery will publish items to redis, node.js will subscribe to redis and get the content into the browser. Example usage from python looks like this:
import redis import json redis_subscribe = redis.StrictRedis() redis_subscribe.publish('socketio_news', json.dumps("Hey, how are you?"))
You need to host socket.io, but nginx does not support websockets. The recommended way is to expose the node.js server directly (which is not a problem because node.js scales).
Can I use this today? Well, yes, but please don’t. Authentication is a problem still. Unless you do many tricks, you can basically only do it for very public data. There’s no authentication between django and node.js. Perhaps store your sessions in redis and check them on connection?
Nice thing: communicating between django and socket.io via redis like this should in theory work for many other usecases. Like letting python talk to ruby or so.
My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.
Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):