pythonWSGI的使用



免费领取服务器

点击领取

pythonWSGI的使用

2023-12-14 8:30:14网络知识悟空

python中WSGI的使用

1、WSGI是Python的Web开发的基石,有两个存在目的:

描述Web服务器如何与Web应用程序交互(将客户端请求传给应用程序);

描述Web应用程序如何处理请求和如何返回数据给服务器。

2、由于Python内置的标准库里有一个WSGI库wsgiref,我们基于他来写一个体现WSGI目的的例子:

fromwsgiref.simple_serverimportmake_server

defapplication(environ,start_response):

status='200OK'

response_headers=[('Content-type','text/html')]

start_response(status,response_headers)

body='

Hello,{name}!!!

'.format(name=environ['PATH_INFO'][1:]or'WSGI')

return[body.encode('utf-8')]

app=make_server('',8000,application)

app.serve_forever()

以上就是Python中WSGI的使用,希望对大家有所帮助。更多Python学习推荐:请关注IT培训机构:筋斗云。

发表评论: