首页IT科技python app框架flash(Python中实现WSGI的框架)

python app框架flash(Python中实现WSGI的框架)

时间2025-08-05 21:07:54分类IT科技浏览7201
导读:1、说明...

1                、说明

Application类对WSGI又做了一层简单的封装                ,由于上面说过WSGI函数返回的是一个可以迭代对象                        ,所以需要实现一个__iter__方法        ,里面控制了客户端的请求路由并且返回不同的输出                。

2                        、实例

fromwsgiref.simple_serverimportmake_server classApplication(object): def__init__(self,environ,start_response): self.start_response=start_response self.path=environ[PATH_INFO] def__iter__(self): ifself.path==/: status=200OK response_headers=[(Content-type,text/html)] self.start_response(status,esponse_headers) yield<h1>Hello,World!</h1>.encode(utf-8) elifself.path==/wsgi: status=200OK response_headers=[(Content-type,text/html)] self.start_response(status,response_headers) yield<h1>Hello,WSGI!</h1>.encode(utf-8) else: status=404NOTFOUND response_headers=[(Content-type,text/html)] self.start_response(status,response_headers) yield<h1>404NOTFOUND</h1>.encode(utf-8) if__name__=="__main__": app=make_server(127.0.0.1,8000,Application) print(ServingHTTPonport8000...) app.serve_forever()

以上就是Python中实现WSGI的框架                ,希望对大家有所帮助                        。更多Python学习推荐:python教学

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
js获取选中的文字(jq如何获取选中option的值_使用jquery操作select(获取选中option的值等))