当前位置: 首页 > 图灵资讯 > 行业资讯> python WSGI规范是什么

python WSGI规范是什么

来源:图灵python
时间: 2024-08-04 17:31:09

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

defsimple_app(environ,start_response):
status='200OK'
response_headers=[('Content-type','text/plain')]
start_response(status,response_headers)
return['Helloworld!\n']

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

importos


defwsgi_server(application):
environ=dict(os.environ.items())

defstart_response(status,response_headers):
print(f'status:{status}')
print(f'response_headers:{response_headers}')

result=application(environ,start_response)
fordatainresult:
print(f'response_body:{data}')

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

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