Skip to content
Advertisement

Tag: flask-sqlalchemy

Flask app getting error of “could not locate flask application. …..FLASK_APP environment variable” for Flask Migrate

I have a file db_table.py that looks like: When I try to run: I get: I tried first manually setting FLASK_APP var, by doing set FLASK_APP=app.py then running flask db init again, but that didn’t resolve the issue. Answer The flask command line argument needs to know what module to locate the current Flask app instance in. Set FLASK_APP as

has no attribute validate_on_submit: How to use wtforms-alchemy’s ModelForm in a flask handler / view

I’m trying to switch from wtforms.ext.sqlalchemy.orm import model_form to using wtforms_alchemy ModelForm: I’m failing miserably… and I’ve been unsuccessful searching for a working example of that uses wtforms_alchemy which shows both the handler and the model. Using model_form works for me: Here’s my working code using model forms: The model script (python): The handler script (python, flask, model_form): The template

Show the SQL generated by Flask-SQLAlchemy

I want to get the SQL issued by Flask-SQLAlchemy queries. In Django, I can print the query attribute to get SQL. How can I get something similar in Flask? Answer Flask-SQLAlchemy records debugging information about all queries during a request. You can get the information with get_debug_queries(). Flask-Debugtoolbar, for example, uses this to offer a debug panel with query timing

Flask-Babel do not translate anything in a web project

Description of my usage: This is my project structure(basically base on Flask Web Development): Configuration in /babel.cfg and /app/__init__.py babel.cfg: app/__init__.py: Then I follow the Flask-Babel document Run $ pybabel extract -F babel.cfg -o messages.pot . Run $ pybabel extract -F babel.cfg -k lazy_gettext -o messages.pot . They do have found all the gettexts and lazy_gettexts. Run $ pybabel init

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

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()

Advertisement