python - getting multiple parameters from url using flask -


  Configure import from flask import flask, jsonify, request ## defined by model on the model of the app and the DB 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') result = PLAY_STORE.query.filter_by (store = store, category = category). All () json_results = [] As a result of results: d = {'rank': result Rank, 'store': results. Store, 'category': results Category, 'Type': Results. Type 'title': result. Tetal} json_results.append (d) back jsonify (item = json_results) if __name__ == '__main__': app.run (debug = true)   

I left one at the top of mysql database I am trying to create an API which is using a flask. In the above program, I am trying to get the store and category from the URL. Even if I use request.args.get , store value is empty, that means json_results is empty. If I make the hard code PLAY_STORE.query.filter_by (Store = "Play Store") I am getting the required output. But when I type 127.0.0.1/app-api?store= "Play Store" json_results is empty.

I have another problem PLAY_STORE.query.filter_by (store = "play store" and category = "games") .

How to filter certain conditions, try this url:

  127.0.0.1:  < / p> 5000 / App-API Store = Play Store and Category = Games   

You do not need to send single quotes in QuickString values.

  & lt; Your host and gt; /? Store = XXXXXX do not like it & lt; Your-host & gt; /? Store = 'XXXXXX'   

In addition, simple inquiries using filter_by , if you want to use complex questions and go through this for more information

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -