google-app-enginehttp-status-code-404url-routingwerkzeugtipfy

Catch-all routing using Tipfy


Using tipfy, how does one express a catch-all route in urls.py if more specific routes do not match?

Tipfy uses Werkzeug-like routing, so there's this (in urls.py):

def get_rules(app): 
rules = [ 
    Rule('/<any>', endpoint='any', handler='apps.main.handlers.MainHandler'), 
    Rule('/', endpoint='main', handler='apps.main.handlers.MainHandler'), 
] 

This will match most random entry points into the application (app.example.com/foo, app.example.com/%20 etc) but does not cover the app.example.com/foo/bar case which results in a 404.

Alternatively, is there a graceful way to handle 404 in Tipfy that I'm missing?


Solution

  • I think you want:

    Rule('/<path:any>', endpoint='any', handler='apps.main.handlers.MainHandler')

    The path matcher also matches slashes.