當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python wsgiref.simple_server.make_server用法及代碼示例

用法:

wsgiref.simple_server.make_server(host, port, app, server_class=WSGIServer, handler_class=WSGIRequestHandler)

創建一個新的 WSGI 服務器監聽hostport, 接受連接app.返回值是提供的實例server_class,並將使用指定的處理請求handler_class.app必須是 WSGI 應用程序對象,定義為 PEP 3333.

示例用法:

from wsgiref.simple_server import make_server, demo_app

with make_server('', 8000, demo_app) as httpd:
    print("Serving HTTP on port 8000...")

    # Respond to requests until process is killed
    httpd.serve_forever()

    # Alternative: serve one request, then exit
    httpd.handle_request()

相關用法


注:本文由純淨天空篩選整理自python.org大神的英文原創作品 wsgiref.simple_server.make_server。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。