test.py 523 B

1234567891011121314151617181920212223242526
  1. class SimpleApp:
  2. def __init__(self):
  3. self.routes = {}
  4. def route(self, path):
  5. def decorator(func):
  6. self.routes[path] = func
  7. return func
  8. return decorator
  9. def execute(self, path):
  10. if path in self.routes:
  11. return self.routes[path]()
  12. else:
  13. raise ValueError("Route not found!")
  14. app = SimpleApp()
  15. @app.route("/")
  16. def home():
  17. return "Welcome to the home page!"
  18. @app.route("/about")
  19. def about():
  20. return "About us page!"