標籤:ica ber pac rtl block line span start height
20170831 基於wsgi的web簡易架構
Request 翻譯為請求Response 翻譯為響應from wsgiref.simple_server import make_serverdef application(environ, start_response): # 通過environ封裝成一個所有請求資訊的對象 # start_response可以很方便的設定回應標頭 start_response(‘200 OK‘, [(‘Content-Type‘, ‘text/html‘)]) return [b"<h1>hello world</h1>"]# 封裝了socket對象以及準備過程(bind, listen)httpd = make_server(‘‘, 8080, application)print(‘Serving HTTP on port 8080...‘)# 開始監聽HTTP請求:httpd.serve_forever()<wiz_code_mirror> x16 1
from wsgiref.simple_server import make_server
2
3
4
def application(environ, start_response):
5
# 通過environ封裝成一個所有請求資訊的對象
6
# start_response可以很方便的設定回應標頭
7
start_response(‘200 OK‘, [(‘Content-Type‘, ‘text/html‘)])
8
return [b"<h1>hello world</h1>"]
9
10
11
# 封裝了socket對象以及準備過程(bind, listen)
12
httpd = make_server(‘‘, 8080, application)
13
14
print(‘Serving HTTP on port 8080...‘)
15
# 開始監聽HTTP請求:
16
httpd.serve_forever()
20170831 基於wsgi的web簡易架構