Hack Forums
[Python] I need assist on python|flask, passing data through url - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] I need assist on python|flask, passing data through url (/showthread.php?tid=5834724)



I need assist on python|flask, passing data through url - TheSteel - May 9, 2018

GET /users/items?returned=false <---- this the url.
Now what i need to do is to create an endpoint that will check on my database for the return status of an item if it is false then all of the items will be returned. I can do everything from checking the db for the return status of an item. What i dont know is how to wtite the URL for the endpont such that when a user vists that endpoint , he or she gets the items whose return status is false. I hope this gives the picture of what i cant implement

since i cantot do this as it wont work
@app.route("/users/items?eturned=false", methods = ['GET'])
def items_unreturned()
.........


RE: I need assist on python|flask, passing data through url - .kr. - May 9, 2018

you code has an issue '@app.route("/users/items?eturned=false", methods = ['GET'])' it should be'returned' like above.

which framework do you use django, flask or tornado?


RE: I need assist on python|flask, passing data through url - Ensky - May 9, 2018

(May 9, 2018 02:07 PM).kr. Wrote:  you code has an issue '@app.route("/users/items?eturned=false", methods = ['GET'])' it should be'returned' like above.

which framework do you use django, flask or tornado?

He's using Flask.




Have you tried passing it through the url as a variable. app.route('users/products?returned=<isReturned>')

Not a false wizard, but hopefully this works.


RE: I need assist on python|flask, passing data through url - DipDuo™ - May 10, 2018

I typically write my urls like:

@app.route('/items/<int:ID>/<name>')
@app.route('/items/<int:ID>/<name>/<category>')
def listItem(ID,name,category=None):
   dostuff()
   return "I did stuff."


RE: I need assist on python|flask, passing data through url - TheSteel - May 13, 2018

I am using flask as @Scapegoat has said. What i dont know is basically how to get parrameters passed via url, but i  think from these suggestions its not much different from passing parameters the body(payload), so let me give it a shot.Thanks guys 🙂 🙂


Now guys one more thing, this needs to be implemented using the returned?=false wizard. what i dont get is the standard or the appropriate way to implement it as i said havin an endpoint such as: "/users/items?returned=false" hard coded like that wont work(i stand corrected though), so the url should i guess allow the user to enter the false value so that the system can querry for the items yet to be returned.The question mark appended at the end of returned must be meaning something right?