💦Python-Decouple
Python Decouple
Decouple helps you to organize your settings so that you can change parameters without having to redeploy your app.
It also makes it easy for you to:
store parameters in ini or .env files;
define comprehensive default values;
properly convert values to the correct data type;
have only one configuration module to rule all your instances.
It was originally designed for Django but became an independent generic tool for separating settings from code.
Install:
pip install python-decouple
Then use it on your settings.py.
Import the config object:
from decouple import config, Csv
Retrieve the configuration parameters:
SECRET_KEY = config('SECRET_KEY')
DEBUG = config('DEBUG', default=False, cast=bool)
For Allowed Host:
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='127.0.0.1', cast=Csv())
Postgres database config:
DATABASES = {
"default": {
"ENGINE": config("ENGINE"),
"NAME": config("DATABASE"),
"USER": config("USER"),
"PASSWORD": config("PASSWORD"),
"HOST": config("HOST", "localhost"),
"PORT": config("PORT", "5432"),
}
}
DEBUG=True
ALLOWED_HOST='.localhost,'
SECRET_KEY=ARANDOMSECRETKEY
ENGINE=django.db.backends.postgresql
DATABASE=<dbname>
USER=<db_username>
PASSWORD=<db_password>
HOST=db
PORT=5432
# This is comment
Last updated
Was this helpful?