import config
from flask import Flask, jsonify, request
## app and db is defined on model.py
from model import db, app, PLAY_STORE
@app.route('/app-api', methods=['GET'])
def listapp():
if request.method == 'GET':
store=request.args.get('store')
category=request.args.get('category')
results = PLAY_STORE.query.filter_by(Store=store,Category=category).all()
json_results = []
for result in results:
d = {'rank': result.Rank,
'store': result.Store,
'category': result.Category,
'type': result.Type,
'title': result.Title}
json_results.append(d)
return jsonify(items=json_results)
if __name__ == '__main__':
app.run(debug=True)
I am trying to build a rest api on top of mysql database using flask.
In the above program I am trying to get the store and category from the url. Even though I use request.args.get
, Store value is empty,i.e json_results is empty.If I hard code making PLAY_STORE.query.filter_by(Store="Play Store")
i am getting the expected output.But when i type 127.0.0.1/app-api?store="Play Store"
json_results is empty.
I have one more issue .How to put multiple conditions in the filter_by, something like PLAY_STORE.query.filter_by(Store="Play Store" and Category="Games")
.