ITPub博客

首页 > IT职业 > IT职场 > python WSGI规范是什么

python WSGI规范是什么

IT职场 作者:tuba 时间:2021-09-11 09:54:38 0 删除 编辑

1、WSGI协议规定,Application端需要成为可调用目标(函数、类别等)。

def simple_app(environ, start_response):
    status = '200 OK'
    response_headers = [('Content-type', 'text/plain')]
    start_response(status, response_headers)
    return ['Hello world!n']

2、Server端也使用函数来实现。

import os
 
 
def wsgi_server(application):
    environ = dict(os.environ.items())
 
    def start_response(status, response_headers):
        print(f'status: {status}')
        print(f'response_headers: {response_headers}')
 
    result = application(environ, start_response)
    for data in result:
        print(f'response_body: {data}')

以上就是python WSGI规范的介绍,希望对大家有所帮助。更多编程基础知识学习:python学习网

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1536/viewspace-2829844/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: python参数是什么
请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    0
  • 访问量
    778