词条 | Web Server Gateway Interface |
释义 |
The Web Server Gateway Interface (WSGI) 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.[1] WSGI was originally specified as PEP-333 in 2003.[2] PEP-3333, published in 2010, updates the specification for Python 3. BackgroundIn 2003, Python web frameworks were typically written against only CGI, FastCGI, mod_python, or some other custom API of a specific web server.[3] To quote PEP 333: Python currently boasts a wide variety of web application frameworks, such as Zope, Quixote, Webware, SkunkWeb, PSO, and Twisted Web -- to name just a few. This wide variety of choices can be a problem for new Python users, because generally speaking, their choice of web framework will limit their choice of usable web servers, and vice versa... 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. WSGI was thus created as an implementation-agnostic interface between web servers and web applications or frameworks to promote common ground for portable web application development.[1] Specification overviewThe WSGI has two sides:
Between the server and the application, there may be one or more WSGI middleware components, which implement both sides of the API, typically in Python code. WSGI does not specify how the Python interpreter should be started, nor how the application object should be loaded or configured, and different frameworks and webservers achieve this in different ways. WSGI MiddlewareA WSGI middleware component is a Python callable that is itself a WSGI application, but may handle requests by delegating to other WSGI applications. These applications can themselves be WSGI middleware components.[4] A middleware component can perform such functions as:[4]
ExamplesExample applicationA WSGI-compatible "Hello, World" application written in Python: Where:
Example of calling an applicationA full example of a WSGI network server is outside the scope of this article. Below is a sketch of how one would call a WSGI application and retrieve its HTTP status line, response headers, and response body, as Python objects.[7] Details of how to construct the WSGI-compatible applications and frameworks{{example farm|section|date=September 2018}}Numerous web frameworks support WSGI: {{div col|colwidth=}}
Currently wrappers are available for FastCGI, CGI, SCGI, AJP (using flup), twisted.web, Apache (using mod_wsgi or mod_python), Nginx (using ngx_http_uwsgi_module),[23] and Microsoft IIS (using WFastCGI,[24] isapi-wsgi,[25] PyISAPIe,[26] or an ASP gateway). See also
References1. ^1 {{cite web|url=https://www.python.org/dev/peps/pep-3333/|title=PEP 3333 - Python Web Server Gateway Interface v1.0.1|last=|first=|date=|website=Python.org|archive-url=|archive-date=|dead-url=|accessdate=2018-04-04}} 2. ^{{Cite web|url=https://www.python.org/dev/peps/pep-0333/|title=PEP 333 -- Python Web Server Gateway Interface v1.0|website=Python.org|language=en|access-date=2018-04-04}} 3. ^{{cite web|url=https://www.python.org/cgi-bin/moinmoin/WebProgramming|title=FrontPage - Python Wiki|date=|website=Python.org|accessdate=2017-01-27}} 4. ^1 {{Cite web|url=https://www.python.org/dev/peps/pep-3333/#middleware-components-that-play-both-sides|title=PEP 3333 -- Python Web Server Gateway Interface v1.0.1|website=Python.org|language=en|access-date=2018-04-04}} 5. ^i.e. "a function, method, class, or an instance with a __call__ method"6. ^{{Cite web|url=https://www.python.org/dev/peps/pep-3333/#environ-variables|title=PEP 3333 -- Python Web Server Gateway Interface v1.0.1|website=Python.org|language=en|access-date=2018-04-04}} 7. ^{{cite web|url=https://www.youtube.com/watch?v=afnDANxsaYo|title=Creating WSGI Middleware - Alan Christopher Thomas - Minted - PythonKC|date=2015-08-28|publisher=YouTube|accessdate=2017-01-27}} 8. ^{{cite web|url=http://bobo.digicool.com |title=プエラリアジェルの効果は? |website=Bobo.digicool.com |date= |accessdate=2017-01-27}} 9. ^{{cite web|url=http://www.djangoproject.com/weblog/2005/jul/18/local_server/ |title=Django without mod_python, and WSGI support | Weblog | Django |website=Djangoproject.com |date=2005-07-18 |accessdate=2017-01-27}} 10. ^{{cite web|author= |url=http://eventlet.net/doc/modules/wsgi.html |title=wsgi – WSGI server — Eventlet 0.20.1 documentation |website=Eventlet.net |date= |accessdate=2017-01-27}} 11. ^{{cite web|url=https://falconframework.org |title=Falcon - Bare-metal web API framework for Python |accessdate=2017-10-22}} 12. ^{{cite web|url=https://pypi.python.org/pypi/gevent-fastcgi |title=gevent-fastcgi 1.0.2.1 : Python Package Index |website=Pypi.python.org |date=2015-12-06 |accessdate=2017-01-27}} 13. ^{{cite web|url=https://github.com/prestans/prestans/ |title=anomaly/prestans: A WSGI compliant REST micro-framework |website=GitHub.com |date= |accessdate=2017-01-27}} 14. ^{{cite web|url=http://code.google.com/p/modwsgi/ |title=Google Code Archive - Long-term storage for Google Code Project Hosting |website=Code.google.com |date= |accessdate=2017-01-27}} 15. ^{{cite web|url=http://pycnic.nullism.com |title=Pycnic Framework |website=Pycnic.nullism.com |date= |accessdate=2017-01-27}} 16. ^{{cite web|url=https://github.com/theintencity/restlite |title=theintencity/restlite: Light-weight RESTful server tools in Python |website=GitHub.com |date= |accessdate=2017-01-27}} 17. ^{{cite web|url=https://github.com/limodou/uliweb |title=limodou/uliweb: Simple and easy use python web framework |website=GitHub.com |date= |accessdate=2017-01-27}} 18. ^{{cite web|url=https://docs.pylonsproject.org/projects/waitress/en/latest/ |title=waitress documentation |website=docs.pylonsproject.org |date= |accessdate=2018-09-26}} 19. ^{{cite web|url=http://webpy.org/ |title=Welcome to |website=Web.py |date=2009-09-11 |accessdate=2017-01-27}} 20. ^{{cite web|url=http://packages.python.org/weblayer |title=weblayer — weblayer v0.4.3 documentation |website=Packages.python.org |date= |accessdate=2017-01-27}} 21. ^{{cite web|url=http://werkzeug.pocoo.org/ |title=Welcome | Werkzeug (The Python WSGI Utility Library) |website=Werkzeug.pocoo.org |date= |accessdate=2017-01-27}} 22. ^{{cite web|url=http://radicale.org/ |title=CalDAV and CardDAV Server - A Simple Calendar and Contact Server |website=Radicale.org |date= |accessdate=2017-01-27}} 23. ^{{cite web|url=http://nginx.org/en/docs/http/ngx_http_uwsgi_module.html |title=Module ngx_http_uwsgi_module |website=Nginx.org |date= |accessdate=2017-01-27}} 24. ^{{cite web|url=https://pytools.codeplex.com/wikipage?title=wfastcgi |title=Python Tools for Visual Studio - Documentation |website=Pytools.codeplex.com |date= |accessdate=2017-01-27}} 25. ^{{cite web|url=http://code.google.com/p/isapi-wsgi/ |title=Google Code Archive - Long-term storage for Google Code Project Hosting |website=Code.google.com |date= |accessdate=2017-01-27}} 26. ^{{cite web|url=http://pyisapie.sourceforge.net/ |title=Python ISAPI Extension for IIS download | SourceForge.net |website=Pyisapie.sourceforge.net |date=2012-04-24 |accessdate=2017-01-27}} External links
1 : Python (programming language) |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。