Configuring the database
If you are using the same virtual environment we have created for the previous example, or you downloaded the code sample, the service
folder already exists. If you created a new virtual environment, create a folder named service
within the root folder for the virtual environment created.
Create a new config.py
file within the service
folder. The following lines show the code that declares variables that determine the configuration for Flask and SQLAlchemy. The SQL_ALCHEMY_DATABASE_URI
variable generates an SQLAlchemy URI for the PostgreSQL database. Make sure you specify the desired database name in the value for DB_NAME
and that you configure the user, password, host, and port based on your PostgreSQL configuration. If you followed the previous steps, use the settings specified in these steps. The code file for the sample is included in the restful_python_2_02_01
folder, in the Flask01/service/config.py
file:
import os basedir = os.path.abspath(os.path.dirname...