Web开发---路由实现
类Flask框架实现 路由route 路由功能实现 路由类实现 #路由 # url = 'http://127.0.0.1:9999/python/index.html?id=5&name=wayne&age=20' # path = '/python/index.html' class Router: ROUTETABLE = {} def register(self,path,handler): self.ROUTETABLE[path] = handler def indexhandler(request): return '<h1>欢迎来到index.html</h1>' def pythonhandler(request): return "<h1>欢迎来到python.html</h1>" router = Router() router.register('/',indexhandler) router.register('/python',pythonhandler) 404处理 注册函数的改造 将注册函数改造成装饰器 class Router: ROUTETABLE = {} @classmethod #注册路由,装饰器 def register(cls,path): def wrapper(handler): cls.ROUTETABLE[path] =