


A detailed discussion of the five commonly used Python web frameworks
There are so many frameworks in Python, and not many people can play them all. Frankly speaking, I have only used three of them to develop projects, and have a little contact with others, so I can only talk about it briefly here. Welcome to know more. Friends added
Speaking of Web Framework, the world of Ruby is dominated by Rails, while Python is a world where a hundred flowers bloom, with countless micro-frameworks and frameworks. For an incomplete list, see:
wiki.python.org/moin/WebFrameworks
Although another major scripting language, PHP, also has many frameworks, they are far less exaggerated than Python. It is precisely because of the Python Web Framework (Python Web Development Framework, There are too many Python frameworks (hereinafter referred to as Python frameworks), so there are always topics about which Python framework is better and worse in the Python community, and the discussion spans even as long as 3-5 years.
There are so many frameworks in Python, and not many people can play them all. Frankly speaking, I have only used three of them to develop projects, and have a little contact with others, so I can only talk about it briefly here. , knowledgeable friends are welcome to add.
Although the Python framework is said to be blooming, there is still one that is the biggest. It's Django. To say that Django is the best among the Python frameworks, some people agree and others firmly disagree. However, if Django has the most complete documentation, the highest market share, and the most job openings, I guess everyone has no objection. The main things that Django is praised for include:
Perfect documentation. I think a large part of Django's success is due to Django's nearly perfect official documentation (including Django book).
Full set of solutions, Django, like Rails, provides a full set of solutions (full-stack framework + batteries included), basically everything you need is available (for example: cache, session, feed, orm, geo, auth), and Django makes them all by itself. Django has basically prepared all the tools for website development for you, so the development efficiency is needless to say, and it is easy to find problems if they arise. , not in your code but in Django’s source code.
Powerful URLRoutingConfiguration, Django allows you to design a very elegant URL. In Django, you can basically say goodbye to ugly GET parameters.
Self-service management backend, admin interface is one of the more eye-catching contribs in Django, allowing you to have a complete backend management interface without writing a single line of code.
The system is tightly coupled. If you feel that a certain function built into Django is not very good, it will be difficult to replace it with your favorite third-party library, such as the ORM and Template mentioned below. It's almost impossible to use SQLAlchemy or Mako in Django, and even with some patches, it will make you feel very, very awkward.
Template function is relatively weak and cannot insert Python code. To write more complex logic, you need to use Python to implement Tag or Filter. There has been a lot of debate about templates. Recently, there are two interesting articles about Python templates for reference:
1 pydanny.blogspot.com/2010/12/stupid-template-languages. html (FQ required)
2 techspot.zzzeek.org/2010/12/04/in-response-to-stupid-template-languages/
Although the URL configuration is powerful, it all needs to be written by hand. This is completely inconsistent with the concept of Convention over configuration of Rails. The URLs assigned by experts and those who are new to Django will be very different.
The database schema has been set for you, so problems arise. For example, many websites require email addresses to be unique, but the value of this field in the schema is not unique, so it is necessary to struggle. .
In general, Django has a lot to offer, and it is very good to use it to quickly develop some Web applications. If you follow Django's design philosophy, you will find Django easy to use and the more you use it, the easier it will become. On the contrary, if you cannot integrate or accept Django's design philosophy, it will be painful for you to use Django. It is best to give up as soon as possible. So in the eyes of some people, Django is no different from an elixir, but to some people it is poison and highly toxic.
Pylons & TurboGears & repoze.bfg
Besides Django, the other big one is Pylons, because TurboGears2.x is based on Pylons, and repoze.bfg has also been incorporated into this large project in the Pylons project, and will not be discussed separately later. TurboGears and repoze.bfg.
The design concepts of Pylons and Django are completely different. Pylons itself only has about two thousand lines of Python code, but it also comes with some third-party modules that are almost used by Pylons. Pylons only provides one shelf and optional solutions. You can freely choose components such as Template, ORM, form, and auth according to your own preferences. The system is highly customizable. We often say that Python is a glue language, so we can definitely say that Pylons is a glue framework designed with glue language.
Choosing Pylons is mostly about choosing its freedom. Choosing freedom also means you choose nightmare:
Learning nightmare, Pylons relies on many third-party libraries, they are not Pylons When you learn Pylons, you also have to learn how to use these libraries. The key is that sometimes you don’t know what you want to learn. The learning curve of Pylons is much higher than that of Django, and the official documentation of Pylons has always been the target of criticism. Fortunately, the book The Definitive Guide to Pylons was published later. This situation has changed. For this reason, Pylons was once known as a Python framework only suitable for experts.
DebuggingA nightmare, because there are many modules involved, and once an error occurs, it is more difficult to locate the problem. It may be the fault of the program you wrote, or it may be that Pylons is wrong, or SQLAlchemy is wrong, or maybe there is a bug in the formencode, it is very messy anyway. This problem can only be solved if you are familiar with it. The integration of Pylons and repoze.bfg may give birth to the next framework that can challenge Django's status.
Tornado& web.py
##Tornado is a Web server (This article will not elaborate on this), and it is also a micro-framework similar to web.py. As a framework, the idea of Tornado mainly comes from Web.py. You can also see the boss of Tornado on the homepage of Web.py website. Bret Taylor said this (the framework he mentioned here for FriendFeed can be regarded as the same thing as Tornado):
Bottle
& Flask
##Bottle and As a representative of the new generation of Python frameworks, Flask is very interesting in that it uses the decorator method to configure URL routing, such as:from bottle import route, run @route('/:name') def index(name='World'): return '<b>Hello %s!</b>' % name run(host='localhost', port=8080)

However, there are still very few successful cases of either Bottle or Flask.
QuixoteThe reason why I want to talk about Quixote in particular is because "Douban.com", the largest website developed in Python in China, was developed using Quixote. I just briefly looked through the source code. I have not done any research and will not comment. I will add more if I have experience. I'm just thinking that if Douban were developed now, there would be more choices.
Others(web2py, uliweb, Karrigell, Werkzeug...)
Last misunderstanding about framework selection
In the framework When it comes to choice, many people easily fall into the following two misunderstandings without knowing it: 1. Which framework is the best - there is no best framework in the world, only the most suitable and suitable for you A framework for your team.
Programming languageThe choice is also the same. If your team is most familiar with Python, use Python. If you are most familiar with Ruby, then use Ruby. Programming languages and frameworks are just tools. They can be used more and faster. , good and economical, it is a good thing after finishing the work.
2. Pay too much attention to performance - In fact, most people don’t need to care too much about the performance of the framework, because the website you develop is simply a small website. There are not many websites that can support 10,000 IPs, and 10 Thousands are even rarer. It doesn't make much sense to talk about performance without a certain amount of visits, because your CPU and memory are always idle. Moreover, languages and frameworks are generally not performance bottlenecks. Performance problems most commonly occur in database access and file reading and writing. PHP's Zend Framework is notoriously slow, but Zend Framework also has big websites, such as digg.com; can't Ruby and Rails, which are often said to have performance problems, still be able to develop twitter? Furthermore, the current cost of hardware and bandwidth is actually very low. Especially with the advent of cloud computing platforms, labor costs are the most expensive. If you don’t have tens of thousands of IPs, you don’t have to worry too much about performance issues. If the traffic increases, spend some money to buy some. The server space is good, and performance problems can be solved simply and quickly.
Note: Some netizens questioned my statement that "Quora was developed using Pylons" is not objective. Let me explain. The website A mentioned here is developed using B, which only means that A mainly or Part of it was developed by B, so don’t worry about whether A uses C.
【Related Recommendations】
1. Free tutorial for getting started with Python
3. Python Object-Oriented Video Tutorial
The above is the detailed content of A detailed discussion of the five commonly used Python web frameworks. For more information, please follow other related articles on the PHP Chinese website!

Python and C each have their own advantages, and the choice should be based on project requirements. 1) Python is suitable for rapid development and data processing due to its concise syntax and dynamic typing. 2)C is suitable for high performance and system programming due to its static typing and manual memory management.

Choosing Python or C depends on project requirements: 1) If you need rapid development, data processing and prototype design, choose Python; 2) If you need high performance, low latency and close hardware control, choose C.

By investing 2 hours of Python learning every day, you can effectively improve your programming skills. 1. Learn new knowledge: read documents or watch tutorials. 2. Practice: Write code and complete exercises. 3. Review: Consolidate the content you have learned. 4. Project practice: Apply what you have learned in actual projects. Such a structured learning plan can help you systematically master Python and achieve career goals.

Methods to learn Python efficiently within two hours include: 1. Review the basic knowledge and ensure that you are familiar with Python installation and basic syntax; 2. Understand the core concepts of Python, such as variables, lists, functions, etc.; 3. Master basic and advanced usage by using examples; 4. Learn common errors and debugging techniques; 5. Apply performance optimization and best practices, such as using list comprehensions and following the PEP8 style guide.

Python is suitable for beginners and data science, and C is suitable for system programming and game development. 1. Python is simple and easy to use, suitable for data science and web development. 2.C provides high performance and control, suitable for game development and system programming. The choice should be based on project needs and personal interests.

Python is more suitable for data science and rapid development, while C is more suitable for high performance and system programming. 1. Python syntax is concise and easy to learn, suitable for data processing and scientific computing. 2.C has complex syntax but excellent performance and is often used in game development and system programming.

It is feasible to invest two hours a day to learn Python. 1. Learn new knowledge: Learn new concepts in one hour, such as lists and dictionaries. 2. Practice and exercises: Use one hour to perform programming exercises, such as writing small programs. Through reasonable planning and perseverance, you can master the core concepts of Python in a short time.

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor