Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

postgres django settings

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'db_name',                      
        'USER': 'db_user',
        'PASSWORD': 'db_user_password',
        'HOST': '',
        'PORT': 'db_port_number',
    }
}
Comment

Add PostgreSQL Settings in Django

# Just after the default DATABASE configuration add this in settings.py

POSTGRES_DB = os.environ.get("POSTGRES_DB")
POSTGRES_PASSWORD = os.environ.get("POSTGRES_PASSWORD")
POSTGRES_USER = os.environ.get("POSTGRES_USER")
POSTGRES_HOST = os.environ.get("POSTGRES_HOST")
POSTGRES_PORT = os.environ.get("POSTGRES_PORT")

POSTGRES_READY = (
    POSTGRES_DB is not None
    and POSTGRES_PASSWORD is not None
    and POSTGRES_USER is not None
    and POSTGRES_HOST is not None
    and POSTGRES_PORT is not None
)

if POSTGRES_READY:
    DATABASES = {
        "default": {
            "ENGINE": "django.db.backends.postgresql",
            "NAME": POSTGRES_DB,
            "USER": POSTGRES_USER,
            "PASSWORD": POSTGRES_PASSWORD,
            "HOST": POSTGRES_HOST,
            "PORT": POSTGRES_PORT,
        }
    }
Comment

PREVIOUS NEXT
Code Example
Python :: get random line from file python 
Python :: drop last row pandas 
Python :: python get username 
Python :: python get file size in mb 
Python :: python install matplotlib 
Python :: python show all columns 
Python :: how to shutdown a computer with python 
Python :: python current year 
Python :: how to convert a column to datetime in pandas 
Python :: change figure size pandas 
Python :: string to datetime convert 
Python :: python spawn shell 
Python :: install django rest framework 
Python :: how to install pyaudio in python 
Python :: install imageio 
Python :: pandas read tab separated file 
Python :: add text toimage cv2 
Python :: seaborn size 
Python :: install streamlit 
Python :: python delete directory if exists 
Python :: minimal flask application import 
Python :: unix to date python 
Python :: python find and replace string in file 
Python :: python flip a coin 
Python :: importlib.reload not working 
Python :: rotate screen trick in python 
Python :: index to datetime pandas 
Python :: animations text terminal python 
Python :: ubuntu install python 3.8 
Python :: full form of ram 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =