先编写hello.py
,实现Web应用程序的WSGI处理函数:
# hello.py def application(environ, start_response): start_response(‘200 OK‘, [(‘Content-Type‘, ‘text/html‘)]) return ‘<h1>Hello, %s!</h1>‘ % (environ[‘PATH_INFO‘][1:] or ‘web‘)
再编写一个server.py
,负责启动WSGI服务器,加载application()
函数:
from wsgiref.simple_server import make_server from hello import application httpd = make_server(‘‘, 8000, application) print "Serving HTTP on port 8000..." httpd.serve_forever()
时间: 2024-10-05 18:32:20