20170831 基於wsgi的web簡易框架
阿新 • • 發佈:2017-09-02
efault nvi black link matching area style attr eas
Request 翻譯為請求
Response 翻譯為響應
<wiz_code_mirror>
x
16
1
20170831 基於wsgi的web簡易框架
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簡易框架