WSGI的全称是Web Server Gateway Interface,即Web服务器网管接口。注意,它不是一个服务器、不是Python模块、不是框架、也不是API程序,它不是任何一种软件,而仅仅是Python语言针对Web服务器和Web应用程序之间通用接口的规范(PEP 3333)。符合WSGI规范的应用程序可以运行在任何符合该规范的Web服务器上。
WSGI规范
WSGI规范十分简单。下面这张时序图展示了WSGI所处的位置,以及调用规则。
1 2 3 4 5 6
Client->Server: request Note right of Server: WSGI Server->Application: app_callable(environ, start_response) Application->Server: start_response(status, response_headers, exc_info=None) Application->Server: return iterator Server->Client: response
Note right of Server: WSGI Server->Application1: Note right of Application1: WSGi Middleware1->Application1: Note right of Middleware1: WSGI Application1->Middleware2: Note right of Middleware2: WSGI Middleware2->Middleware3: Note right of Middleware3: WSGI Middleware3->Application2: Application2->Middleware3: Middleware3->Middleware2: Middleware2->Middleware1: Middleware1->Application1: