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

前端 未结 2 962
失恋的感觉
失恋的感觉 2021-01-30 03:43

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

相关标签:
2条回答
  • 2021-01-30 04:30

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

    0 讨论(0)
  • 2021-01-30 04:38
    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
    0 讨论(0)
提交回复
热议问题