Compare the advantages and disadvantages of mainstream Python web frameworks

Source: Internet
Author: User
Tags auth zend zend framework in python

When it comes to web Framework,ruby's world of rails unified, Python is a world of blossoming, micro-framework, the framework of countless, incomplete list see: http:// Wiki.python.org/moin/webframeworks. While another big scripting language PHP has many frameworks, it's far less exaggerated than python, because the Python web framework (Python Web Development Framework, hereinafter referred to as the Python framework) is too much, So in the Python community there are always topics about the pros and cons of the Python framework, and the time span of the discussion is even 3-5 years.

Python so many frameworks, can play a lot of people are not many, frankly, I have only used one of the three development projects, and some slightly contact, so here can only talk about, welcome to the knowledgeable friends to add, Pat bricks.

Django

Although the Python framework is said to be a blossom, there is still one of the biggest, it is Django. To say that Django is the best in the Python framework, there are some who agree and disagree, but say that Django has the best documentation, the highest market share, and the maximum number of jobs to expect. Django's main areas of praise are:
The perfect document, Django's success, I think is largely due to Django's near-perfect official document (including the Django book).
A full range of solutions, Django, like rails, offers a full range of solutions (Full-stack Framework + batteries included), basically what you want (e.g. cache, session, feed, ORM, GEO , auth), and all Django built their own, the development of Web site should also launch tools Django is basically for you to do, so the development efficiency is needless to say, out of the problem is easy to find, not in your code in the Django source.
Powerful URL routing configuration, Django allows you to design a very elegant URL, in Django you can basically say goodbye to ugly get parameters.
Self-help management backstage, admin interface is Django more eye-catching a contrib, so that you almost do not have to write a line of code to have a complete background management interface.
Django's main drawback is that Django insists on making all of its own wheels, the system is relatively closed, and Django's most criticized place is:

System tight coupling, if you think that the Django built-in function is not very good, want to use a favorite Third-party library to replace it is difficult, such as the following will be said Orm, Template. It's almost impossible to use SQLAlchemy or Mako in Django, even if you have some patches on it that will make you feel very awkward.
Django's own ORM is far less powerful than the sqlalchemy, except that in Django, where SQLAlchemy is the de facto ORM standard in the Python world, other frameworks support SQLAlchemy, But Django still sticks to his own set. The Django Developer's support for SQLAlchemy has also been discussed and tried, but eventually dropped, presumably at a cost too high and hard to get together with other Django modules.
The template function is weak and cannot be plugged into Python code, and a more complex logic needs to be implemented with the addition of tag or filter in Python. There has been a lot of controversy over the template, and there have been two more interesting articles about Python templates available for your reference:
Http://pydanny.blogspot.com/2010/12/stupid-template-languages.html (need to flip wall)
http://techspot.zzzeek.org/2010/12/04/in-response-to-stupid-template-languages/
The URL configuration is powerful, but all hand-written, which is completely contrary to rails ' convention over configuration's idea, and the URL of the master and the first-known Django will vary greatly.
The tangled auth module, the Django Auth with other modules tightly, the function is very strong, is to do a bit over, the user's database schema all to you set up, so the problem comes, such as many sites require email address only, But the value of this field in a schema is not unique, and entanglement is a must.
The python file is a configuration file, not a more common form of INI, XML, or YAML. This is not a problem in itself, but because theoretically the value of the settings can be changed dynamically (although it is not the case), this is not the embodiment of best practice.
In general, Django Taibaodalan, it's nice to use it to quickly develop some Web applications. If you follow Django's design philosophy, you'll find Django very useful and more fun, but if you can't fit in or accept Django's design philosophy, you'll have to be miserable with Django and give up early. So in some people's eyes Django is a panacea, but for some people it is poison and poisonous.

The Django case has disqus.com, bitbucket.org, poster net and so on.

pylons & TurboGears & REPOZE.BFG


Besides Django, another big head is pylons, because turbogears2.x is based on pylons, and REPOZE.BFG has been incorporated into the larger project in pylons project, TurboGears and REPOZE.BFG are no longer discussed separately.

Pylons and Django are completely different, pylons itself has only about 2000 lines of Python code, but it comes with a number of third-party modules that are almost pylons. Pylons only provides a shelf and alternative options, you can choose according to their own preferences template, ORM, form, auth and other components, the system highly customizable. We often say that Python is a glue language (glue language), so we can say that pylons is a glue frame designed with glue language:

The choice of pylons is to choose its freedom, the choice of freedom also indicates that you choose a nightmare:

Learning nightmares, pylons rely on many third-party libraries, they are not pylons, you learn pylons also have to learn how to use these libraries, the key sometimes you do not know what you want to learn. Pylons's learning curve is much higher than Django's, and pylons's official document has been the subject of criticism, but the definitive Guide to pylons book has changed. For this reason, pylons was once hailed as a Python framework only for use by the master.
Debug nightmares, because there are many modules involved, once the error occurred it is more difficult to locate the problem where. May be you write the program's fault, it may be pylons error, or sqlalchemy error, make a mistake is formencode have bugs, anyway very messy. This problem can be solved only if it is used very well.
Upgrade nightmare, install pylons large and small total to install nearly 20 Python modules, each have their own version number, to upgrade the version of Pylons, which module out of the incompatibility of the problem are possible, the upgrade is basically difficult difficult. So far Reddit pylons still stay on the antique 0.9.6, sqlalchemy or 0.5.3 version, should be related to this article. So everybody play pylons must combine virtualenv to play, give oneself leave a path, otherwise will die very miserably.
The fusion of pylons and REPOZE.BFG may lead to the next framework to challenge the Django status.

Pylons cases are reddit.com, dropbox.com, quora.com and so on.

Tornado & web.py

Tornado is a Web server (not detailed in this article), At the same time is a class web.py micro-framework, as the frame tornado idea mainly comes from web.py, everybody in web.py's homepage also can see Tornado's big guy Bret Taylor's passage (the frame he says here FriendFeed with Tornado can be seen as a thing):

[web.py inspired the] web framework we use the [and] the WebApp framework, "ships with App Engine ..."

Because of this relationship, Tornado is no longer discussed separately.

Web.py's design philosophy seeks to be streamlined (Keep it simple and powerful), with a total of few lines of code, and unlike pylons, which relies on a large number of third-party modules, but provides something necessary for only one framework, such as: URL routing, Template, Database access, the rest to the user to do their own.

The advantage of a streamlined framework is that you can focus on the business logic without having to worry too much about the framework itself or the interference of the framework, and the shortcomings are obvious, and many things you have to do yourself.
I personally prefer this streamlined framework, because you can easily read the source to understand the entire framework of the working mechanism, if the frame that piece is not very agreeable, I could monkey patch a little bit according to their own requirements.

The early Reddit were written in web.py, and the tornado cases were friendfeed.com, bit.ly, Quora.com and my open source site poweredsites.org.

Bottle & Flask


Bottle and flask as representatives of the new generation of Python frameworks, it's interesting to configure URL routing in a decorator way, such as:

From bottle import route, run

@route ('/:name ')
def index (name= ' World '):
Return ' <b> Hello%s!</b> '% name

Run (host= ' localhost ', port=8080)
Bottle, flask, like web.py, are very streamlined, bottle even all the code is in that Ching line of. py file. In addition flask and pylons like, can with JINJA2, SQLAlchemy and so on the combination is very good.

But there are still few successful cases, whether bottle or flask.

Quixote
The reason to specifically say Quixote, is because the country's largest use of Python Web site "Douban" is developed with Quixote. I simply flipped the source code, did not do research, do not comment, have experience to add. I'm just thinking, if douban to develop now, there should be more choices.

Others (Web2py, Uliweb, Karrigell, Werkzeug ...) )
Welcome everyone to add ...

Finally on the misunderstanding of frame selection
In the framework of the choice of issues, many people are easily caught in the following two misunderstandings without knowing:

Which frame is best-there is no best frame in the world, only the one that best suits you and the team that best suits you. Programming language selection is also the truth that your team Python is best used in Python. If the most familiar is Ruby, then use Ruby good, programming language, framework are just tools, can many, fast, good, province of the dry finish is a good thing, pipe TMD is the Japanese or the United States Emperor made it!

Pay too much attention to performance-in fact, most people do not need to be too concerned about the performance of the framework, because you develop the site is a small station, can be 10,000 of the IP site is not much, on the 100,000 is very few. It doesn't make much sense to talk about performance before you have a certain amount of traffic, because your CPU and memory are always idle. Also, language and frameworks are not typically performance bottlenecks, and performance problems are most often found in database access and file reading and writing. PHP's Zend Framework is very slow, but the Zend framework has the same stations, such as: digg.com, is often said to have performance problems of Ruby and rails, can not still develop Twitter? In addition, now the hardware, bandwidth costs is very low, especially with the cloud computing platform, the human cost is the most expensive, not tens of thousands of IP at all do not care about performance problems, traffic went up to spend some money to buy some server space well, simple and fast to solve performance problems.

Note: The previous netizen question me "Quora is develops with the pylons" this kind of argument is not objective, special explanation, here said a site A is developed with B, just refers to a major or part of the development by B, we do not go to tangle a also use C.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.