In Cherrypy it's possible to do this:
@cherrypy.expose def default(self, url, *suburl, **kwarg): pass
Is there a flask equivalent?
By default, a route only answers to GET requests. You can use the methods argument of the route() decorator to handle different HTTP methods. If GET is present, Flask automatically adds support for the HEAD method and handles HEAD requests according to the HTTP RFC.
Routing in FlaskThe route() decorator in Flask is used to bind an URL to a function. As a result when the URL is mentioned in the browser, the function is executed to give the result. Here, URL '/hello' rule is bound to the hello_world() function.
Adding routes is quite easy, all we need to do is use the Python decorator again followed by a new function. An 'about' route is shown highlighted here. After adding this code, the development server expectedly notices the change and reloads the server for us.
There is a snippet on Flask's website about a 'catch-all' route for flask. You can find it here.
Basically the decorator works by chaining two URL filters. The example on the page is:
@app.route('/', defaults={'path': ''}) @app.route('/<path:path>') def catch_all(path): return 'You want path: %s' % path
Which would give you:
% curl 127.0.0.1:5000 # Matches the first rule You want path: % curl 127.0.0.1:5000/foo/bar # Matches the second rule You want path: foo/bar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With