Is Tornado a replacement to Django or are they complementary to each other?
Solution 1:
To answer the question,
-
NO, Tornado is not a replacement to Django. It's an alternative.
-
YES, they are complementary to each other but not in the same process (*)
I would use Django when it's a big team effort and/or needs to run on a SQL database.
I would use Tornado for everything else. Ie. personal projects, WebSocket-related apps, or apps that use a NoSQL backend.
(*) Don't bother running Django inside Tornado or the other way around unless you really have a strong requirement for that.
Solution 2:
Tornado is a web server and a web framework by most definitions, but it's quite a minimal framework (compared to Rails or Django). Tornado modules are loosely coupled, so it's possible to use just the web server component (or even just the lower level IO loop). Compared to Django, there are a lot of areas where Tornado doesn't have as much functionality. For example, there isn't really a model abstraction in Tornado, you have to roll your own.
When you run a Tornado app behind Nginx, that's your app running – Nginx just proxies to it. I believe Tomcat is an application server, distinct from your application. I wouldn't call Tomcat a web framework.
Django is not asynchronous, so generally your app will block while using the Django components. This may not be a big deal, it depends what you're doing. The Tornado devs have stated (paraphrasing heavily) that for most applications, the biggest win comes from not blocking while waiting for the client, i.e. web browser. Blocking on the database, for example, is not a big deal if you keep your queries fast.
There are a lot of pros and cons for both Django and Tornado, and there are many alternatives to both - it's definitely not just a choice between the two. Here's a very quick list of why you might want to use Django though:
Pros for Django:
- it's a fuller stack (admin pages for example are very easy to implement)
- it's much more established (plugins, tutorials, etc.)
- it's better documented
- its ORM is very nice