The sort order comes from the order parameter in the request:
order = {'asc': 1, 'desc': -1}[request.args.get('order', 'asc')]
But you'll see that there's no validation of the parameter, so that passing ?order=bug results in a KeyError exception and a "500 Internal Server Error" response.
A more robust (and shorter!) alternative would be something like this:
order = -1 if request.args.get('order') == 'desc' else 1
The sort order comes from the
order
parameter in the request:But you'll see that there's no validation of the parameter, so that passing
?order=bug
results in aKeyError
exception and a "500 Internal Server Error" response.A more robust (and shorter!) alternative would be something like this: