I am building a straight-forward Flask API. After each decorator for the API endpoint, I have to define a function that simply calls another function I have in a separate file. This works fine, but seems redundant. I would rather just call that pre-defined function directly, instead of having to wrap it within another function right after the decorator. Is this possible?
What I have currently:
import routes.Locations as Locations
# POST: /api/v1/locations
@app.route('/locations', methods=['GET'])
def LocationsRead ():
return Locations.read()
Locations.read() function looks like this:
def read():
return {
'id': 1,
'name': 'READ'
}
What I am hoping to do:
import routes.Locations as Locations
# POST: /api/v1/locations
@app.route('/locations', methods=['GET'])
Locations.read()
@app.route(...)(Locations.read)
. But be aware that it might surprise other people coming to your code@app.route('/api/v1/locations/<int:id>', methods=["GET"])(Locations.read(id))
I am assuming that this alternative way of doing it won't accept arguments?