


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!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

VS Code extensions pose malicious risks, such as hiding malicious code, exploiting vulnerabilities, and masturbating as legitimate extensions. Methods to identify malicious extensions include: checking publishers, reading comments, checking code, and installing with caution. Security measures also include: security awareness, good habits, regular updates and antivirus software.

In VS Code, you can run the program in the terminal through the following steps: Prepare the code and open the integrated terminal to ensure that the code directory is consistent with the terminal working directory. Select the run command according to the programming language (such as Python's python your_file_name.py) to check whether it runs successfully and resolve errors. Use the debugger to improve debugging efficiency.

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.
