WSGI全称为Web Server Gateway Interface,WSGI容许web框架和web服务器分开,能够混合匹配web服务器和web框架,选择一个适合的配对。好比,能够在Gunicorn 或者 Nginx/uWSGI 或者 Waitress上运行 Django, Flask, 或 Pyramid。html
web服务器必须具有wsgi接口,全部的现代Python web框架都以具有wsgi接口,它不让你对代码做修改就能使服务器和web框架协同工做。java
其余语言也有相似的接口:java中的servletpython
WSGI接口的定义很是简单,它只是要求web开发者实现一个函数,就能够相应http请求。咱们来看一个最简单的Web版本的“Hello, World!”:web
def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) return 'Hello World!'
上面的 application() 函数就是符合WSGI标准的一个HTTP处理函数,它接收两个参数:浏览器
函数的返回值Hello, World!将做为HTTP响应的Body发送给浏览器。
application()函数必须由WSGI服务器来调用。服务器