views:

536

answers:

1

How do I use Django with the Tornado web server?

+1  A: 

Both Tornado and Django are webserver, they allow you to write pages using Python and both support templates. To mix those together you need something to direct certain http request to Tornado and some to Django. I use Nginx for this and it works really nice. In the Nginx config you could now use proxy_pass to direct you calls like this:

location /comet {
  proxy_pass http://localhost:8081;
}

location / {
  proxy_pass http://localhost:8080;
}

You could also config your proxy to use more than one Tornado server to share the load (Tornado is single threaded and should be run one instance/core).

So to get started with Tornado I suggest that you start with some of the demos that comes with it, in you case I would study the chat example. You could easily rip out the OpenID stuff and concentrate on the comet stuff.

MyGGaN
Django is not a web server. It comes with a basic web server to aid in developing Django projects, but which is not suitable to be used in production environments.
Ignacio Vazquez-Abrams
Completely right, though I assumed that xRobot was using Django (with it's webserver) as a complete webserver/framework for building his web project. I spared him the details.
MyGGaN
I have played with chat and tornado on my computer and it works perfectly. On my server I am using nginx and django framework but I don't know where to put Tornado.P.s. Have you tried also the Push Module for Nginx ?Thanks ;)
xRobot
Sorry, I have not. But what do you mean with "put Tornado"? I have my Tornado source in a subfolder for my project and then I start it with: sudo nginx -c conf/nginx.conf
MyGGaN
ah ok... I will insert Tornado source in a subfolder.Thanks ^_^
xRobot
Did my answer help you out alright?
MyGGaN