Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think <a href="https://stackoverflow.com/questions/219110/how-python-web-frameworks-wsgi-and-cgi-fit-together/219124#219124">Florian's answer</a> answers the part of your question about "what is WSGI", especially if you read <a href="http://www.python.org/dev/peps/pep-0333" rel="nofollow noreferrer">the PEP</a>.</p> <p>As for the questions you pose towards the end:</p> <p>WSGI, CGI, FastCGI etc. are all protocols for a web server to <em>run code</em>, and deliver the dynamic content that is produced. Compare this to static web serving, where a plain HTML file is basically delivered as is to the client.</p> <p><strong>CGI, FastCGI and SCGI are language agnostic.</strong> You can write CGI scripts in Perl, Python, C, bash, whatever. CGI defines <em>which</em> executable will be called, based on the URL, and <em>how</em> it will be called: the arguments and environment. It also defines how the return value should be passed back to the web server once your executable is finished. The variations are basically optimisations to be able to handle more requests, reduce latency and so on; the basic concept is the same.</p> <p><strong>WSGI is Python only.</strong> Rather than a language agnostic protocol, a standard function signature is defined:</p> <pre><code>def simple_app(environ, start_response): """Simplest possible application object""" status = '200 OK' response_headers = [('Content-type','text/plain')] start_response(status, response_headers) return ['Hello world!\n'] </code></pre> <p>That is a complete (if limited) WSGI application. A web server with WSGI support (such as Apache with mod_wsgi) can invoke this function whenever a request arrives.</p> <p>The reason this is so great is that we can avoid the messy step of converting from a HTTP GET/POST to CGI to Python, and back again on the way out. It's a much more direct, clean and efficient linkage.</p> <p>It also makes it much easier to have long-running frameworks running behind web servers, if all that needs to be done for a request is a function call. With plain CGI, you'd have to <a href="http://tools.cherrypy.org/wiki/RunAsCGI" rel="nofollow noreferrer">start your whole framework up</a> for each individual request.</p> <p>To have WSGI support, you'll need to have installed a WSGI module (like <a href="http://code.google.com/p/modwsgi/" rel="nofollow noreferrer">mod_wsgi</a>), or use a web server with WSGI baked in (like <a href="http://tools.cherrypy.org/" rel="nofollow noreferrer">CherryPy</a>). If neither of those are possible, you <em>could</em> use the CGI-WSGI bridge given in the PEP.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload