1.15.1.6 The runCGI() Method

You may not be in a situation where you have access to a WSGI server. The Python web modules also come with a code to allow WSGI applications and middleware to be run in a CGI environment such as Apache.

If you want to run a WSGI as a CGI application you need to turn it back into one. This can be done very simply by using the middleware component web.wsgi.runCGI as shown below:

def application(environ, start_response):
    start_response('200 OK', [('Content-type','text/plain')])
    return ['Hello world!']

import web.wsgi.cgi
web.wsgi.runCGI(application)

The application can then be run in a normal CGI webserver.

To test this approach run webserver.py using python webserver.py in the scripts directory and visit http://localhost:8000/doc/src/lib/wsgi-simple-cgi.py to see a sample CGI WSGI application running.