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 field for each item I bind to the form? view form template I am unable to get my data to
Tag: flask
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 doing under the hood. Why
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 is at least unescaping (of
PostgreSQL ILIKE query with SQLAlchemy
I’d like to run a query that selects all posts, case insensitive, that have titles that match ‘%’ + [some_phrase] + ‘%’. That is, select all rows that have titles that contain some phrase, case insensitive. From the research I’ve done, it looks like I need to use Postgres’s ILIKE query for it to match case insensitive. How can I
Creating seed data in a flask-migrate or alembic migration
How can I insert some seed data in my first migration? If the migration is not the best place for this, then what is the best practice? Answer Alembic has, as one of its operation, bulk_insert(). The documentation gives the following example (with some fixes I’ve included): Note too that the alembic has an execute() operation, which is just like
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
I’m not able to import Flask-WTF TextField and BooleanField
I’m using virtualenv to set up a new project. I installed a lot of things using virtualenv pip from the script folder like below: I have no other packages installed in the global python folder. My code looks like this: and other packages are found like sqlalchemy also installed only in the virtual environment. The error I get is: Form
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