8

我有一个简单的 web 应用程序要构建,我刚刚开始搞乱 mod_wsgi。在各种教程中,第一个 hello world 应用程序如下所示:

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]

然后,稍后该应用程序包含一个使用 wsgiref 的 wsgi 服务器,一些变体:

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()

该应用程序在没有服务器的情况下工作,那么服务器是做什么用的?

4

1 回答 1

7

我猜本教程假设您没有设置和运行 mod_wsgi。这样,您可以从命令行运行脚本,它将启动wsgiref运行应用程序的服务器,这样您就可以测试它而无需安装 Apache 和 mod_wsgi。

于 2011-03-11T19:50:41.370 回答