get to know wsgi

What is WSGI?

WSGI, the full name of Web Server Gateway Interface, or Python Web Server Gateway Interface, is a simple and universal interface between a Web server and a Web application or framework defined for the Python language. Similar interfaces have appeared in many other languages ​​since WSGI was developed.

The official definition of WSGI  is, the Python Web Server Gateway Interface. As can be seen from the name, this thing is a Gateway, that is, a gateway. The role of the gateway is to convert between protocols.

WSGI serves as a low-level interface between a Web server and a Web application or application framework to enhance the common denominator of portable Web application development. WSGI is based on existing CGI standards.

Many frameworks come with WSGI server, such as Flask, webpy, Django, CherryPy, etc. Of course, the performance is not good. The built-in web server is more for testing purposes. When publishing, the WSGI server in the production environment is used or nginx is used for uwsgi.

  •  
    In other words, WSGI is like a bridge, one side is connected to the web server, the other side is connected to the user's application. However, the function of this bridge is very weak, and sometimes it needs the help of other bridges to process it. The role of WSGI is shown in the figure:

The role of WSGI

WSGI has two sides: the "server" or "gateway" side, and the "application" or "application framework" side. The service side calls the application side, provides context information, and a callback function (provided to the application to pass message headers to the server side), and receives the web content as a return value.

So-called WSGI middleware implements both sides of the API and thus can mediate between WSGI services and WSGI applications: from the perspective of the WSGI server, the middleware acts as the application, and from the perspective of the application, Middleware acts as a server. The "middleware" component can perform the following functions:

  • After rewriting the environment variables, the request message is routed to different application objects according to the target URL.
  • Allows multiple applications or application frameworks to run concurrently in one process.
  • Load balancing and remoting, by forwarding request and response messages over the network.
  • Do content post-processing, such as applying XSLT style sheets.

WSGI's design does refer to Java's servlets. http://www.python.org/dev/peps/pep-0333/ has this passage:

By contrast, although Java has just as many web application frameworks available, Java's "servlet" API makes it possible for applications written with any Java web application framework to run in any web server that supports the servlet API.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324812899&siteId=291194637