Why use wsgiref simple_server?

I have a simple webapp to build and am just starting to mess with mod_wsgi. In various tutorials, the first hello world application looks something like this:

def application(environ,start_response):
   response_body = 'Hello World'
   status = '200 OK'

   response_headers = [('Content-Type', 'text/plain'),
                       ('Content-Length', str(len(response_body)))]

   start_response(status, response_headers)
   return [response_body]

Then, the later application includes a wsgi server using wsgiref, some options:

from wsgiref.simple_server import make_server

def application(environ, start_response):
    response_body = 'Hello World'
    status = '200 OK'

    response_headers = [('Content-Type', 'text/plain'),
                           ('Content-Length', str(len(response_body)))]

    start_response(status, response_headers)
    return [response_body]

httpd = make_server('localhost', 8000, application)
httpd.serve_forever()

The application works without a server, so why do I need a server?

+5
source share
1 answer

I assume the tutorial assumes that you do not have mod_wsgi configured and running. This way you can run the script from the command line and it will start the server wsgirefrunning the application so that you can test it without installing Apache and mod_wsgi.

+7

All Articles