Django and Comet
Creating real time event driven components in your Django applications using Orbited Comet server.
The basic solution of Comet powered application is to hide comet inside our web page handled by standard HTTP server. We can make a orbited.cfg config file in a folder from which we run orbited server with settings:
All requests to /chat will be handled by orbited, others will be redirected to http://127.0.0.1:8080 where a Django development server may be running with our chat. To get the site use port 8000 in which orbited is running (django application is "hidden" behind orbited).
[global] proxy.enabled = 1 proxy.keepalive = 0 [proxy] /chat -> ORBITED / -> http://127.0.0.1:8080
Create a django project with with "chat" application. No database needed, just one template and some static files. Create chat.html template: This template will show the chat "form" The iframe will be used to handle events from/to chat "box". In static files folder create chat.css: And chat.js: ajaxroutines.js file you can download from dynamicdrive.com. We use it to send GET ajax requests easily. We send requests to two django views that handle sending messages and login users, urls.py: Our views: Now run the orbited server and django dev server. Open 2 browser windows and go to http://localhost:8000/. You should see the form. Add a nickname and hit the "nickname" button. You can now send messages. When you "login" to the chat in the next window a info will show in the first windows chat. Now sending message in one window will show up in both - like in real chat: More info and pylons, cherrypy examples on the project page.