知行编程网知行编程网  2022-11-01 21:30 知行编程网 隐藏边栏  1 
文章评分 0 次,平均分 0.0
导语: 本文主要介绍了关于python WSGI规范是什么的相关知识,希望可以帮到处于编程学习途中的小伙伴

什么是 python WSGI 规范


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}')


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

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写
扫一扫二维码分享