<option id="mwy0y"><strong id="mwy0y"></strong></option>
  • <ul id="mwy0y"><sup id="mwy0y"></sup></ul>
  • <ul id="mwy0y"></ul>
  • <del id="mwy0y"><dfn id="mwy0y"></dfn></del><ul id="mwy0y"><sup id="mwy0y"></sup></ul>
  • <abbr id="mwy0y"></abbr>

    千鋒教育-做有情懷、有良心、有品質(zhì)的職業(yè)教育機(jī)構(gòu)

    400-811-9990
    手機(jī)站
    千鋒教育

    千鋒學(xué)習(xí)站 | 隨時(shí)隨地免費(fèi)學(xué)

    千鋒教育

    掃一掃進(jìn)入千鋒手機(jī)站

    領(lǐng)取全套視頻
    千鋒教育

    關(guān)注千鋒學(xué)習(xí)站小程序
    隨時(shí)隨地免費(fèi)學(xué)習(xí)課程

    上海
    • 北京
    • 鄭州
    • 武漢
    • 成都
    • 西安
    • 沈陽(yáng)
    • 廣州
    • 南京
    • 深圳
    • 大連
    • 青島
    • 杭州
    • 重慶
    當(dāng)前位置:長(zhǎng)沙千鋒IT培訓(xùn)  >  技術(shù)干貨  >  python實(shí)現(xiàn)WSGI的框架

    python實(shí)現(xiàn)WSGI的框架

    來(lái)源:千鋒教育
    發(fā)布人:xqq
    時(shí)間: 2023-11-13 08:19:35

    python中實(shí)現(xiàn)WSGI的框架

    1、說(shuō)明

    Application類對(duì)WSGI又做了一層簡(jiǎn)單的封裝,由于上面說(shuō)過(guò)WSGI函數(shù)返回的是一個(gè)可以迭代對(duì)象,所以需要實(shí)現(xiàn)一個(gè)__iter__方法,里面控制了客戶端的請(qǐng)求路由并且返回不同的輸出。

    2、實(shí)例

    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'

    Hello,World!

    '.encode('utf-8')

    elifself.path=='/wsgi':

    status='200OK'

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

    self.start_response(status,response_headers)

    yield'

    Hello,WSGI!

    '.encode('utf-8')

    else:

    status='404NOTFOUND'

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

    self.start_response(status,response_headers)

    yield'

    404NOTFOUND

    '.encode('utf-8')

    if__name__=="__main__":

    app=make_server('127.0.0.1',8000,Application)

    print('ServingHTTPonport8000...')

    app.serve_forever()

    以上就是Python中實(shí)現(xiàn)WSGI的框架,希望對(duì)大家有所幫助。更多Python學(xué)習(xí)推薦:請(qǐng)關(guān)注IT培訓(xùn)機(jī)構(gòu):千鋒教育。

    聲明:本站稿件版權(quán)均屬千鋒教育所有,未經(jīng)許可不得擅自轉(zhuǎn)載。

    猜你喜歡LIKE

    python實(shí)現(xiàn)WSGI的框架

    2023-11-13

    python打開(kāi)文本文件有哪些方法?

    2023-11-13

    python使用loguru操作日志

    2023-11-13

    最新文章NEW

    python-=是什么意思

    2023-11-13

    pythonre是什么?

    2023-11-13

    python列表追加元素出錯(cuò)的解決

    2023-11-13

    相關(guān)推薦HOT

    更多>>

    快速通道 更多>>

    最新開(kāi)班信息 更多>>

    網(wǎng)友熱搜 更多>>