WSGI是Web Server Gateway Interface的簡稱。它不是服務器,python模塊,框架,API和任何種類的軟件。它僅僅是一個服務器和應用間的接口規范。
from wsgiref.simple_server import make_server def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) # 請求頭信息 return [b'<h1>hello world!</h1>'] # 返回body信息 a = 8080 # 設置端口 httpd = make_server('', a, application) httpd.serve_forever() # 設置服務一直啟動
運行文件后,在瀏覽器輸入:localhost:8080(設置的端口號)即可訪問到啟動的服務