1Python Full Stack Road Series web Framework Introduction

Source: Internet
Author: User

Introduction to the web framework of the Python full stack Road series


The essence of all language Web框架 is actually a socket server, listening to a port, and then running.

Web框架Consists of two parts, one part is the socket logical processing of the business, and different processing according to the request

Python is Web框架 divided into two categories,

    1. That is, the socket also contains the business logic processing (tornado)

    2. Does not include sockets (the framework itself implements sockets through third-party modules) only includes business logic processing (DJANGO,FLASK)

wsgi is web Server Gateway Interface , translated is the WEB server gateways interface. Specifically, WSGI is a specification that defines how Web servers interact with Python applications so that Web applications written using Python can be interfaced with Web servers. WSGI was first defined in PEP-0333, and the latest version is defined in Python's PEP-3333.

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/91/F5/wKioL1j5tbfS3m_3AAEUN6DYSvI362.png-wh_500x0-wm_ 3-wmp_4-s_514526187.png "title=" 1pythonpep-333 definition. png "width=", "height=" 398 "border=" 0 "hspace=" 0 "vspace=" 0 "style = "WIDTH:700PX;HEIGHT:398PX;" alt= "Wkiol1j5tbfs3m_3aaeun6dysvi362.png-wh_50"/>

The code in the following example RunServer() is a function of an HTTP handler that conforms to the WSGI standard, which receives two parameters:

    1. environ : A Dict object that contains all the HTTP request information;

    2. start_response : A function that sends an HTTP response;

wsgirefthe module implements a customweb框架

The approximate logic of the code is: two functions definedindex()Andmanage()If the URL that the user accesses is127.0.0.1:8000/indexwill return, if the user is accessing the127.0.0.1:8000/managewill return/manage, if you visit another page, return404

#!/usr/bin/python2# _*_coding:utf-8 _*_from wsgiref.simple_server import make_ Serverdef index (ARG):    #  returns a string containing HTML code     return  " 

To access the test through the Curl command on this machine

[Email protected]:~$ Curl 127.0.0.1:8000/index

No matter how complex the Web application, the portal is a wsgi the handler function. All input information for HTTP requests can be via environ obtained, the output of the HTTP response can be start_response () plus the function return value as body, complex web application, the light of a wsgi function to deal with or too low, we need to abstract the web framework above the WSGI to further simplify web development.

MVC and MTV

The MVC pattern is one of the architectural patterns, and the purpose of the MVC pattern is to implement a dynamic programming design that simplifies the subsequent modification and expansion of the program and makes it possible to reuse a part of the program. In addition, this mode makes the programming more intuitive by simplifying the complexity.

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/91/F5/wKiom1j5tdiRc3VPAAAX7GQbjnA071.png-wh_500x0-wm_ 3-wmp_4-s_755778369.png "title=" 2mvc.png "width=" "height=" 397 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width : 600px;height:397px; "alt=" Wkiom1j5tdirc3vpaaax7gqbjna071.png-wh_50 "/>

The software system is separated by the basic parts of itself and also gives the functions of the basic parts. Professionals can be grouped by their own expertise:

  1. 控制器Controller-Responsible for forwarding the request and processing the request;

  2. 视图View-Interface designer for graphic interface design;

  3. 模型Model-Programmers to write the functions that the program should have (real algorithm and so on), database experts for data Management and database design (can be implemented specific functions);

In MVC.Mis RepresentativeMODLE层,VRepresentVIEWLayer, C stands forContrlLayer.
MTV in theMis RepresentativeMODLE层,TRepresentTemplate(模板层),VRepresentVIEWLayer.

#Python全栈之路


This article is from the "Eden" blog, reprint please contact the author!

1Python Full Stack Road Series web Framework Introduction

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.