Django vs Tornado

There are at least two major reasons:

Batteries included with Django: ORM, sessions, authentication, admin, etc.

Tremendous ecosystem of apps (addons) and tools that Django community has built over the years

Tornado's own web site refers to it as a "web server and networking library" rather than a "framework". It feels nice on small projects where none of the above is necessary and if you need to serve many long-standing connections you don't have much choice, but in all other cases Django will come way far ahead in terms of productivity.

知乎使用的是Tornado框架。因为它支持异步,很适合做实时Comet应用,而且简单轻量,学习成本低,再就是有FriendFeed的成熟案例,Facebook的社区支持。知乎的产品有个特性,就是希望跟浏览器端建立一个长连接,便于实时推送Feed和通知,所以Tornado比较合适。

----------------

To me, a big Tornado fan, a MAJOR plus for Django is it's ORM. If you have a SQL database, use Django.

-----------

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

推荐阅读更多精彩内容