一个简单的web框架实现
#!/usr/bin/env python
# -- coding: utf-8 --
__author__ = 'EchoRep'
from wsgiref.simple_server import make_server
def index():
#
data = open('html/index.html').read()
return data
def echo():
#
data = open('html/echo.html').read()
return data
url_list=[
('/echo',echo),
('/index',index),
]
def RunServer(environ,start_response):
start_response('200 OK',[('Content-Type','text/html')])
#
#
#
request_url = environ['PATH_INFO']
#
#
#
#
#
#
#
for url in url_list:
if request_url == url[0]:
return url[1]()
else:
return "404"
if __name__ == '__main__':
httpd = make_server('',8000,RunServer)
print "Server HTTP on port 8000..."
httpd.serve_forever()