自定义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()

 

    原文作者:飞鸟_山东
    原文地址: https://www.cnblogs.com/wenxianfeng/p/10358030.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞