Tornado、Bottle以及Flask

         最近接手一个Tornado项目代码,项目要在原有基础上做很大扩展,为了更好地吃透并扩展好这个项目,就对Tornado以及比较轻型的Bottle、Flask这些框架一一作了调研。其实若干年前做第一个PythonWeb项目的时候,也对很多框架作了横向调研,不过当时的调研比较表面,这次的调研对各框架的文档作了比较细致的通读。Django不在其列,是因为对Django比较熟悉,不需要调研,不过Django可能作为标杆来对以上三者作为评判

        第一个:原先代码使用的框架Tornado,首先Tornado的定位:Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed. By using non-blocking network I/O, Tornado can scale to tens of thousands of open connections, making it ideal for long pollingWebSockets, and other applications that require a long-lived connection to each user.,这个是官文档的原文,事实文档内容比例也说明其asynchronous networking library的内容比例还是很大的。这样下来其Web Framework的比例就相对很小了,于是其Library的特性导致它的Web框架玩法与其他框架比起来相对比较原始。再就是官方文档中的By using non-blocking network I/O, Tornado can scale to tens of thousands of open connections, making it ideal for long pollingWebSockets 这一句说明了Tornado真正的个性强项,一个异步Web库勉为其难做Web Framework和Django比起来真是太原始粗糙了。

     第二个:Bottle,Tornado文档pdf是200来页,Bottle是100来页,flask是300多页,Bottle is amicroframework designed for prototyping and building small web applications and services.Bottle的特性对于它这个定位来说是足够了。

     第三个:Flask,Flask号称微内核框架,他的文档中有一段对micro的解释,充分表明他的设计方向:“Micro” does not mean that your whole web application has to fit into a single python file (although it certainly can), nor does it mean that Flask is lacking in functionality. The “micro” in microframework means Flask aims to keep the core simple but extensible. Flask won’t make many decisions for you, such as what database to use. Those decisions that it does make, such as what templating engine to use, are easy to change. Everything else is up to you, so that Flask can be everything you need and nothing you don’t. 这种设计风格正好和Django截然反之,Django是All in one,在技术设施层所需要的工作和决策非常少,Flask却给开发者敞开了扩展的空间。

原文地址:https://www.cnblogs.com/dhcn/p/7130503.html