In Flask-RESTful we add an api route like the below so that GET /api/kitty –> to CuteKitty.get() method; like this for all HTTP verbs Lets say that I need to provide my api consumers with a cute api like How can i achive the above routing with api.add_resource Like wise how to add route like /api/kitty/<int:kitty_id>/habits –> CuteKitty.habits(kitty_id) Answer Flask-RESTful
Tag: flask
Print raw HTTP request in Flask or WSGI
I am debugging a microcontroller I’ve built which is writing raw HTTP requests line by line. I am using Flask for my backend and I would like to see the entire request as it appears in this format: I know Flask is based on WSGI. Is there anyway to get this to work with Flask? […]
What are Flask Blueprints, exactly?
I have read the official Flask documentation on Blueprints and even one or two blog posts on using them. I’ve even used them in my web app, but I don’t completely understand what they are or how they …
How can I create a form from a list of models using WTForms?
I have a list of Prediction models. I want to bind them to a form and allow the use to post back. How can I structure my form so the post associates a Home/Away score with a Prediction model’s id …
demystify Flask app.secret_key
If app.secret_key isn’t set, Flask will not allow you to set or access the session dictionary. This is all that the flask user guide has to say on the subject. I am very new to web development and I have no idea how/why any security stuff works. I would like to understand what Flask is […]
Flask, setting JSON in a cookie, and decoding it on the client (in javascript)
I’m setting a cookie in Flask like follows : If i print json.dumps(someObject) on the server I get : On the client side it becomes : I want to decode it on a javascript client what format is it exactly ? I’d like to decode it and pass it to angular.fromJson(), it looks like there […]
Add a prefix to all Flask routes
I have a prefix that I want to add to every route. Right now I add a constant to the route at every definition. Is there a way to do this automatically? Answer The answer depends on how you are serving this application. Sub-mounted inside of another WSGI container Assuming that you are going to run this application inside of
How to upload a file using an ajax call in flask
Hi I’m quite new to flask and I want to upload a file using an ajax call to the server. As mentioned in the documentation, I added a file upload to the html as folows: and I wrote the ajax handler as this I do not know how to get the uploaded file (not the name) from this and save
How to execute raw SQL in Flask-SQLAlchemy app
How do you execute raw SQL in SQLAlchemy? I have a python web app that runs on flask and interfaces to the database through SQLAlchemy. I need a way to run the raw SQL. The query involves multiple table joins along with Inline views. I’ve tried: But I keep getting gateway errors. Answer Have you tried: or: Note that db.engine.execute()
Playing a wavefile from the html using flask framework?
This is my run.py code This my base.html file this my tasks.html This my s1.html In the s1.html i have a hyperlink to a audio wav file . I want to play the audio file from the s1.html. The wav file is present in the root directory. It is throwing error GET /ps.wav HTTP/1.1″ 404 Please tell how to solve