WSGI acquaintance Interface

WSGI

Called the WSGI the Web Server Gateway Interface , WSGI web server allows a web and separated from the frame, can be mixed and matched web web server framework, to select a suitable pair. For example, you can run Django, Flask, Pyramid or on Gunicorn or Nginx / uWSGI or Waitress.

web server must have wsgi interfaces, all modern Python web frameworks to have wsgi interface, which let you make changes you can make server and web frameworks work together on the code.

Other languages ​​have similar interfaces: java servlet in

WSGI defined interfaces

WSGI interface definition is very simple, it only requires a web developers to implement a function, the corresponding http request can. Let's look at a simple Web version of "Hello, World!":

def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])
    return 'Hello World!'

Above file application () function is an HTTP handler WSGI-compatible application, which accepts two parameters:

  • environ: a dictionary object that contains all the http request information.
  • The start_response: transmitting a HTTP response function, which accepts two parameters:
    • http response code.
    • A group represented by the HTTP header list, each with a header containing the two str tuple representation.

Function's return value Hello, World! Will be sent to the browser as the Body HTTP response.
application () function must be called by WSGI server.

Published 44 original articles · won praise 8 · views 2448

Guess you like

Origin blog.csdn.net/qq_39659278/article/details/100185082