Following the example in this question I have a little flask
view that filters data based on querystring arguments:
@app.route('/regs')
def regs_data():
#check what data is available
#REGS is a sqlalchemy model
cols = REGS.__table__.columns.keys()
kwargs = {}
for k, v in request.args.lists():
if k not in cols:
abort(400, "helpful err msg")
#takes only first occurrence
kwargs[k]=v[0]
my_query = REGS.query.filter_by(**kwargs).all()
#....modify the query data for return
return the_data_as_json
This works great for when there is only 1 occurence of each key in request.args
. How can I extend this to cope with multiple values for each keyword? e.g /regs?foo=1&foo=2
Is there a way to apply both filter_by
and in_()
Thanks