Open vijayelango opened 3 years ago
https://knowledge.udacity.com/questions/222447
import os
SECRET_KEY = os.urandom(32)
# Grabs the folder where the script runs.
basedir = os.path.abspath(os.path.dirname(__file__))
# Enable debug mode.
DEBUG = True
# Connect to the database
# TODO DONE: IMPLEMENT DATABASE URL
SQLALCHEMY_DATABASE_URI = 'postgresql://databaseuser:password@localhost:5432/database_name'
You can then import the SQLALCHEMY_DATABASE_URI and use it wherever you want to use it in your project.
``
https://knowledge.udacity.com/questions/132219
There is a principle of separation of concerns which says, Separation of Concerns (SoC) is a design principle for separating a computer program into distinct sections such that each section addresses a separate concern. A concern is a set of information that affects the code of a computer program. A concern can be as general as "the details of the hardware for an application", or as specific as "the name of which class to instantiate"
In short : Don’t write your program as one solid block, instead, break up the code into chunks that are finalized tiny pieces of the system each able to complete a simple distinct job.
So if you are following the principle of separation of concerns then what you will do is that you will define your models in a different file and then configuration for database in a different files and then different routes for the API in a different class, etc and then there will be one file in which you will be adding all these to make whatever you thought of!
Benefits:
So what you will do in config.py is you will put out the SQL_ALCHEMY_DATABASE_URI and then you will import the same in the file app.py.This way whenever you intend to change the SQL_ALCHEMY_DATABASE_URI then you will just look for the file config.py and then you are done!
This way you can be more reliable on working with your team because you know what you all have to do is you just need to import SQL_ALCHEMY_DATABASE_URI from the file config.py and the other teammate which is working with config.py will have to just make sure that he/she results out the SQL_ALCHEMY_DATABASE_URI and he/she does not need to worry about anything else going in other file!
Connect to a local postgresql database. Find out how to connect through config.py.