代码在界面上打不开
发表在Python图书答疑
2019-02-23 悬赏:4 学分
《零基础学Python》第15章 Web编程
是否精华
是
否
版块置顶:
是
否
from wsgiref.simple_server import make_server
def app(environ,start_response):
start_response('200 ok',[('Content-Type','text/htm;charset=utf-8'),( 'Date','Sat, 23 Feb 2019 09:19:04 GMT')])
## print('*'*10)
## print(environ['PATH_INFO'])
## print('*'*10)
file_name=environ['PATH_INFO'][1:] or'index.html'
HTML_ROOT_DRT= './Viems/'
try:
file = open(HTML_ROOT_DRT+file_name,'rb')
except:
response ='File is not found'
else:
file_data=file.read()
file.close()
response =file_data.decode('utf-8')
return [response.encode('utf-8')]
if __name__ =="__main__":
ser =make_server('',8000,app)
ser.serve_forever()