Sending data to the PostgreSQL database from a Flask app
Interacting with a database is a common aspect of most web applications. Sending data to the PostgreSQL database from a Flask app is simple and straightforward. A web application would not be complete without the ability to store and retrieve data from a database.
The first step in sending data to a database is to ensure there is a connection between the Flask app and the database. This involves installing the required libraries and ensuring that you work in a virtual environment to contain your installation and prevent unexpected occurrences, due to the interference of other libraries.
Let’s make use of the bizza/backend
directory created in the Setting up the development environment with Flask section of Chapter 1. You can create one if you haven’t already. Install and activate the virtual environment.
To create a virtual environment, open your project root directory in a terminal and add the following...