首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >【说站】python WSGI规范是什么

【说站】python WSGI规范是什么

作者头像
很酷的站长
发布于 2022-11-24 15:47:06
发布于 2022-11-24 15:47:06
4440
举报

python WSGI规范是什么

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

代码语言:javascript
复制
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端也使用函数来实现。

代码语言:javascript
复制
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规范的介绍,希望对大家有所帮助。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • python WSGI规范是什么
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档