我有一个简单的webapp要构建,而我才刚刚开始尝试使用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服务器,wsgiref的一些变体:
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()应用程序在没有服务器的情况下工作,那么服务器是用来做什么的?
发布于 2011-03-12 03:50:41
我猜本教程假定您尚未设置并运行mod_wsgi。这样,您就可以从命令行运行该脚本,它将启动运行该应用程序的wsgiref服务器,这样您就可以在不安装Apache和mod_wsgi的情况下对其进行测试。
https://stackoverflow.com/questions/5277448
复制相似问题