把mvc或mtv框架的model資料庫,view:html,control邏輯處理,url判別,wsgiref集中在一個文件 代碼如下 ...
把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()