Is Tornado a replacement to Django or are they complementary to each other?

DjangoTornado

Django Problem Overview


I have several questions about Tornado and other web frameworks.

  1. Tornado claims to be a webserver (a non-blocking one, therefore much performant), so some people said it does not play the role of django --i.e., they say tornado is not a web framework.

However, it does provide a web framework I think (http://www.tornadoweb.org/documentation#main-modules) -- in this way, it seems to replace django as the web development framework.

Is my above understanding correct?

  1. Normally, several Tornados are set up behind Nginx. Tomcat is also normally set up behind Apache web server. Can I say Tornado plays exactly same role of Tomcat does for Java web server? If the answer is yes, then Tornado IS a web framework.

  2. I read some article saying using Tornado and Django together, such as http://www.jeremybowers.com/blog/post/3/on-deploying-tornado-web-server-framework/, but I read some article online claiming that "if you use Django, then you lose the asynchronous from Tornado", is this true or false? A related question though, if Tornado is itself a web framework as I said in 1), why people bother using Django at all? (to result the plugin?)

Can someone give me a 101 introduction?

Django Solutions


Solution 1 - Django

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 - Django

  1. 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.

  2. 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.

  3. 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionchenView Question on Stackoverflow
Solution 1 - DjangoPeter BengtssonView Answer on Stackoverflow
Solution 2 - DjangoCole MacleanView Answer on Stackoverflow