Flask URL Route: Route All other URLs to some function

Issue

I am working with Flask 0.9. I have experience with Google App Engine.

  1. In GAE, the url match patterns are evaluated in the order they appear, first come first serve. Is it the same case in Flask?

  2. In Flask, how to write a url match pattern to deal with all other unmatched urls. In GAE, you only need to put /.* in the end, like: ('/.*', Not_Found). How to do the same thing in Flask since Flask wont support Regex.

Solution

  1. I think this is the answer http://flask.pocoo.org/docs/design/#the-routing-system
  2. If you need to handle all urls not found on server — just create 404 hanlder:

    @app.errorhandler(404)
    def page_not_found(e):
        # your processing here
        return result
    

Answered By – cleg

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published