python中的wsgi协议

WSGI协议

  • wsgi 就是实现了web 服务器和框架解耦的一种规定。
  • 定义框架中要实现一个函数application,并且这个函数接受两个参数env,start_response
  • env:一个包含所有HTTP请求信息的dict对象,
  • start_response:一个发送HTTP响应的函数。该函数主要生成响应的头部header内容。
  • 调用的过程,当web 服务器调用框架中的application 函数时,会携带两个参数env和start_response,start_response 调用完成之后,会生成响应的头部,把头部存在web服务器中,application 会根据env 传过来的请求信息进行处理,生成body ,把body返回给web服务器。
    == web 服务器的作用是:完成数据的整合和请求的调度==
def application(env,start_response):
    start_response('200 OK',[('Content-Type','text/html;charset=utf-8'),("server","mini_frame v1.0")])
    file_name = env["PATH_INFO"]
    if file_name =="/index.py":
        return index()
    elif file_name == "/center.py":
        return center()
    else:
        return "hello world! 还有谁 。。。。\r\n"

猜你喜欢

转载自blog.csdn.net/weixin_44224529/article/details/88751992