Flask Routing Catch-all route


It may be useful to have one catch-all view where you handle complex logic yourself based on the path. This example uses two rules: The first rule specifically catches / and the second rule catches arbitrary paths with the built-in path converter. The path converter matches any string (including slashes) See Flask Variable-Rules

@app.route('/', defaults={'u_path': ''})
def catch_all(u_path):
c = app.test_client()
c.get('/')  # u_path = ''
c.get('/hello')  # u_path = 'hello'
c.get('/hello/stack/overflow/')  # u_path = 'hello/stack/overflow/'