July 2019
Beginner to intermediate
302 pages
9h 38m
English
Flask-SQLAlchemy is the extension that provides the SQLAlchemy interface for Flask.
This extension can simply be installed by using pip as follows:
$ pip3 install flask-sqlalchemy
The first thing to keep in mind with Flask-SQLAlchemy is the application configuration parameter that tells SQLAlchemy about the location of the database to be used:
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ('DATABASE_URI')
SQLALCHEMY_DATABASE_URI is a combination of the database protocol, any authentication needed, and also the name of the database. In the case of SQLite, this would look something like the following:
sqlite:////tmp/test.db
In the case of PostgreSQL, it would look like the following:
postgresql://yourusername:yourpassword@localhost/yournewdb. ...