新聞中心
這里有您想知道的互聯(lián)網營銷解決方案
創(chuàng)新互聯(lián)Python教程:Python中實現(xiàn)WSGI的框架
1、說明

創(chuàng)新互聯(lián)成立與2013年,是專業(yè)互聯(lián)網技術服務公司,擁有項目成都做網站、網站設計網站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元五華做網站,已為上家服務,為五華各地企業(yè)和個人服務,聯(lián)系電話:18982081108
Application類對WSGI又做了一層簡單的封裝,由于上面說過WSGI函數(shù)返回的是一個可以迭代對象,所以需要實現(xiàn)一個__iter__方法,里面控制了客戶端的請求路由并且返回不同的輸出。
2、實例
from wsgiref.simple_server import make_server
class Application(object):
def __init__(self, environ, start_response):
self.start_response = start_response
self.path = environ['PATH_INFO']
def __iter__(self):
if self.path == '/':
status = '200 OK'
response_headers = [('Content-type', 'text/html')]
self.start_response(status, esponse_headers)
yield 'Hello,World!
'.encode('utf-8')
elif self.path == '/wsgi':
status = '200 OK'
response_headers = [('Content-type', 'text/html')]
self.start_response(status, response_headers)
yield 'Hello,WSGI!
'.encode('utf-8')
else:
status = '404 NOT FOUND'
response_headers = [('Content-type', 'text/html')]
self.start_response(status, response_headers)
yield '404 NOT FOUND
'.encode('utf-8')
if __name__ == "__main__":
app = make_server('127.0.0.1', 8000, Application)
print('Serving HTTP on port 8000...')
app.serve_forever()以上就是python中實現(xiàn)WSGI的框架,希望對大家有所幫助。更多Python學習推薦:python教學
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
當前文章:創(chuàng)新互聯(lián)Python教程:Python中實現(xiàn)WSGI的框架
URL分享:http://m.5511xx.com/article/coideoh.html


咨詢
建站咨詢
