码迷,mamicode.com
首页 > Web开发 > 详细

20170831 基于wsgi的web简易框架

时间:2017-09-02 13:00:28      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:ica   ber   pac   rtl   block   line   span   start   height   

20170831 基于wsgi的web简易框架

Request    翻译为请求
Response    翻译为响应
<wiz_code_mirror>
 
 
 
x
16
 
 
 
 
 
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简易框架

标签:ica   ber   pac   rtl   block   line   span   start   height   

原文地址:http://www.cnblogs.com/gengwenhao/p/7466305.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!