request = "/test1.py" urls = [ ("/test1.py", "test1"), ("/test2.py", "test2"), ] def test1(): print("----1----") def test2(): print("----2----") for url, handler in urls: if request == url: handler()