创新互联Python教程:pythonWSGI规范是什么

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电脑。

网站标题:创新互联Python教程:pythonWSGI规范是什么
分享地址:http://www.hantingmc.com/qtweb/news4/369854.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联