from wsgiref.simple_server import make_serverdef index(): return ‘index‘def login(): return ‘login‘def routes(): urlpatterns=( (‘/index‘,index), (‘/login‘,login), ) return urlpatternsdef runserver(environ,start_response): start_response(‘200 OK‘ , [(‘Content-Type‘,‘text/html‘)]) url = environ[‘PATH_INFO‘] urlpatterns = routes() func = None for item in urlpatterns: print (item) if item[0] == url: func=item[1] break if func: a=func() return a else: return ‘hhhhh404 404‘if __name__ == ‘__main__‘: httpd= make_server(‘192.168.6.163‘,8000,runserver) print (‘start web server‘) httpd.serve_forever()
时间: 2024-10-20 06:02:46