Aug-25-2019, 05:03 AM
Essentially, a decorator allows you to put extra behaviour around a function (i.e. before/after it). They do this by returning a new function that does what the original one does but between that extra behaviour (and hence, a decorator is a higher order function).
In Flask, a decorator (
In Flask, a decorator (
Flask.route
is used to associate request handling functions with URL paths. The extra behaviour in this case is to basically store that association in a dictionary, so that when a request for a particular path comes in, the correct function can be called. In my codebase at work (albeit in Scala, not Python), we're using the decorator idea to record metrics on the response times in our application.