Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common Web development frameworks for Python?

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about the common Python Web development framework, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Today, there are many development frameworks in Python to help you easily create web applications. The significance of web development framework is to build applications quickly and easily without paying attention to unnecessary technical details (protocols, messages, data structures).

By 2020, there are many web applications based on Python, such as youtube.com, instagram, reditt, domestic Zhihu, Douban and so on. These sites are implemented using different web frameworks, which we will talk about one by one today.

1. Django

Django should be the most well-known and representative Web framework of Python. Its name comes from Django Reinhardt, a French composer and guitarist. In early 2000, in order to develop online applications for newspaper newspapers, two programmers at a newspaper began to write websites in Python, and finally summed up their work into an open source framework, which is today's Django.

Django follows the MVC development pattern and names this pattern MTV (MTV pattern is unique to Python)

M Model (data model for back-end database model definition and processing module)

T Templates (template for front-end display information)

V View (view, used to receive client requests, process Model, render return information to the client, etc.).

(1) advantages and disadvantages of Django:

Advantages:

One-stop development solution, package check-in

The integration of various components is highly mature and fully configured.

User model and authority authentication system are sound.

ORM database management function is simple and convenient.

Has its own background management function.

Disadvantages:

Configuration is relatively complex

The simple application of Django has a feeling of killing a chicken with a cow knife.

(2) Django installation and initialization

There are two ways to download Django:

Install directly through pip:

Pip install Django==3.0.3

Download and install from the source code:

Git clone https://github.com/django/django.git

After installation, create a new django project test_django/ with the startproject parameter.

Django-admin.py startproject test_django

Cd test_django enter the project path and enter the startup service command to start the simplest django service.

Python manage.py runserver

Finally, visit the default path http://127.0.0.1:8000 to see the effect of django project launch.

Started successfully, now you can write your Django code.

2. Flask

If Django is the representative of large and comprehensive solutions, then Flask is the representative of small and sophisticated solutions.

Flask is a lightweight web development framework based on Werkzeug toolkit. It is mainly oriented to Web applets with simple requirements and short project cycle.

Flask this framework is relatively flexible, the core idea is that Flask only completes the basic functions, other functions are completed by a variety of third-party plug-ins to achieve a high level of module customization.

(1) the common Flask plug-ins are as follows:

Flask-SQLalchemy: manipulating databases

Flask-migrate: managing the migration database

Flask-Mail: Mail

Flask-WTF: form

Flask-script: inserting script

Flask-Login: authenticate user statu

Flask-RESTful: a tool for developing REST API

Flask-Bootstrap: integrated front-end Twitter Bootstrap framework

Flask-Moment: localization date and time

The two main core applications of Flask are Werkzeug and template engine Jinja. Apart from that, everything else can be assembled freely and is suitable for cleanliness addicted programmers.

(2) advantages and disadvantages of Flask

Advantages:

The project structure and configuration are simple.

Components can be disassembled and assembled freely

Small or temporary projects are more suitable.

Disadvantages:

The high degree of customization of components brings about serious compatibility problems between various components. It is not suitable for large applications. For example, the blueprint mechanism is far worse than the url configuration of Django.

(2) Flask installation

We install directly through pip:

Pip install flask

Create a new py file, hello.py, anywhere.

From flask import FlaskFlaskapp = Flask (_ _ name__) @ app.route ("/") def hello (): return "Hello World!" if _ _ name__ = = "_ main__": app.run ()

Enter the startup command:

Python hello.py* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Finally, visit the default address http://127.0.0.1:5000 to open the flask default launch page.

3. Tornado

Strictly speaking, Tornado is not a Web framework, but an asynchronous processing framework based on Python implementation, only with related functions of WSGI processing.

Tornado and Flask, except for the basic Web processing functions and templates, other functional components need to be assembled by themselves.

(1) the advantages and disadvantages of tornado

Advantages:

Short and short, good performance, independent of Python multi-process / multi-thread

Support for asynchronous non-blocking IO processing

Websocket is supported.

Disadvantages:

Too concise, only suitable for pure interface services or small website applications.

(2) Tornado installation

Pip is also used for installation.

Pip install tornado

Create a new hello.py code file.

Import tornado.webimport tornado.ioloopclass IndexHandler (tornado.web.RequestHandler): def get (self): self.write ('hello world') if _ _ name__ = =' _ _ main__': # create the application object app = tornado.web.Application ([(ringing _ handler)]) # bind the listening port app.listen (8888) # start the web program tornado.ioloop.IOLoop.current (). Start ()

Finally, execute python hello.py to start the tornado service and access the initialization page through http://127.0.0.1:8888.

The above three are the Web frameworks that are often used in Python development, and some that are not so commonly used are also briefly introduced.

4. TurboGears

It is said that Douban was developed based on this framework in its early days.

TurboGears is a framework assembled on several well-known Python projects, made up of SQLAlchemy,WebOb,Repoze,Genshi.

In a sense, TurboGears is about gluing multiple open source components together. The same MVC architecture is used as Django.

Advantages of TurboGears:

Support for aggregation

Powerful object relational mapper

Transaction system supports transactions between multiple databases

Multi-database support

Using reusable code snippets as templates

Has a lot of flexibility to dock non-standard components

Support for sharding

The template system makes the designer's design easier.

5. Bottle

Bottle, like Flask, is a lightweight Web development framework.

It does not depend on any libraries outside the Python standard library. Created in 2009, it only starts with the smallest tool that contains templates, routing, and a WSGI abstraction layer. It is a good choice for programmers to find the lightest WSGI service, which can be used to create a Web service as quickly as possible.

Advantages of Bootle:

Ultra lightweight

Built-in template engine and support for Jinja2,Mako and Cheetah.

Summary

Today, I introduce to you a variety of Python Web development framework, my personal commonly used framework mainly includes Django, Flask, Tornado. Other frameworks dabble less because of popularity and ease of use.

For the three most commonly used frameworks, I would like to give you a piece of advice:

Formal projects, large projects, to determine the need for long-term development and maintenance of the project recommended to choose Django, once and for all, do not have to consider too much.

Small projects, temporary projects, not afraid of trouble, you can choose Flask.

For small projects, temporary projects or some simple interface services, you can choose Tornado. Because Tornado inherently supports asynchronism, many people who need to do asynchronous IO services can also choose Tornado. In addition, Django3.0 has begun to fully support asynchronism. It is recommended that you wait and see.

After reading the above, do you have any further understanding of the common Web development frameworks of Python? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report