# 客户端函数,environ包含所有HTTP请求的dict对象,start_response则是作为http请求响应的函数
def application(environ,start_response):
# http响应的header
start_response('200 OK',[('Content-Type','text/html')])
# http响应的body
return [b'<h1>Hello,web,goodbye,web!</h1>']
#启动WSGI进行测试一下,打开浏览器,输入:http://localhost:8000
# 导入python标准库中的wagiref模块中的simple_server中的make_serve方法
from wsgiref.simple_server import make_server
# 导入application函数
from main import application
# 用make_server方法创建一个简单的服务器,ip地址为本机,端口号为8000
# 并处理导入的application函数
httpd=make_server('127.0.0.1',8000,application)
# 输出的提示内容
print('Serving HTTP on port 8000...')
# 使用aerve_forever()监听http请求
httpd.serve_forever()
# 更加动态的获取用户名
# 客户端函数,environ包含所有HTTP请求的dict对象,start_response则是作为http请求响应的函数
def application(environ,start_response):
# http响应的header
start_response('200 OK',[('Content-Type','text/html')])
# http响应的body
body='<h1>Hello,%s</h1>'%(environ['PATH_INFO'][1:] or 'web')
return [body.encode('utf-8')]
WSGI
最新推荐文章于 2022-02-07 10:34:14 发布