自定义mvc或mtv框架:基于wsgiref的web框架

把mvc或mtv框架的model数据库,view:html,control逻辑处理,url判别,wsgiref集中在一个文件

代码如下

 1 #!/usr/bin/env python
 2 #-*- coding:utf-8 -*-
 3 
 4 from wsgiref.simple_server import  make_server
 5 def new():
 6     f = open('add.html','r')
 7     data = f.read()
 8     f.close()
 9     return data
10 def old():
11     return '222'
12 dic = {'/new':new,'/old':old}
13 def RunServer(environ,start_respone):
14     start_respone('200 0k',[('content-type','text/html')])
15     vv = environ['PATH_INFO']
16     if vv in dic.keys():
17         val = dic[vv]
18         return val()
19     else:
20         return '404'
21 if __name__ == '__main__':
22     httpd = make_server('',8000,RunServer)
23     httpd.serve_forever()

 

posted @ 2019-02-09 21:09  飞鸟_山东  阅读(222)  评论(0编辑  收藏  举报