python WSGI规范是什么

260次阅读
没有评论

python

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}')
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2021-07-13发表,共计646字。
新手QQ群:570568346,欢迎进群讨论 Python51学习