综述
此文目的
Flask是Python下非常流行的一种Web开发框架,但是作为Web框架,Flask又是如何接收来自远程的请求并作出响应的呢,通过查资料、看源码和进行简单的实验,我想弄清楚这样的一个实现过程
WSGI协议
Web Server Gateway Interface,以下来自Wikipedia
The Web Server Gateway Interface (WSGI, pronounced whiskey[1][2] or WIZ-ghee[3]) is a simple calling convention for web servers to forward requests to web applications or frameworks written in the Python programming language. The current version of WSGI, version 1.0.1, is specified in Python Enhancement Proposal (PEP) 3333.[4]
WSGI was originally specified as PEP-333 in 2003.[5] PEP-3333, published in 2010, updates the specification for Python 3.
WSGI是用来在web服务器向用Python写的Web应用/框架传递请求的调用约定,在PEP-333/PEP-3333提出,是为了解决各Python程序和web server交互的乱象
一个简单的Web接口
在Python中,我们可以使用wsgiref来实现一个简单的web接口