WEB框架之wsgi框架

#_author:来童星
#date:2020/2/20
#wsgi 框架
from wsgiref.simple_server import make_server
#environ为一个对象,封装了客户端的请求信息(environ是一个包含所有请求信息的dict对象)
#start_response为服务器发送给浏览器(客户端)的响应信息
def application(environ,start_response):
start_response("200 ok ",[('Content-Type','text/html')])
return [b"<h1>hello star</h>"]

#wsgi作用:
#1.wsgi帮我们封装了socket对象以及准备过程(准备过程包括 socket对象的创建,bind,listen)
#2.通过environ将所有请求信息封装成一个对象
#3.通过start_response可以很方便的设置响应头
httpd=make_server('',8080,application)
print('sereing HTTP is running on port 8080 ')

#开始监听HTTP请求
httpd.serve_forever()


原文地址:https://www.cnblogs.com/startl/p/12336429.html