I am trying to create my own kind of project structure by looking at two scoops of django. The project structure looks something like this
.envs
.local
.django
.postgres
.production
.django
.postgres
in postgres inside local, the following items are listed
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_DB=marketing
POSTGRES_USER=username
POSTGRES_PASSWORD=password
DATABASE_URL=postgres://username:password@localhost:5432/marketing
the settings file is divided into 3 parts as base.py, local.py and production.py
in base.py, I have configured the DATABASES
key as following
DATABASES = {
'default': env.db('DATABASE_URL'),
}
However I am getting an error
django.core.exceptions.ImproperlyConfigured: Set the DATABASE_URL environment variable
Though, I have DATABASE_URL
in .envs/.local/.postgres, I am getting above error. Why is that so?
Add export before your variables in .myfilename
.
export POSTGRES_HOST=postgres
export POSTGRES_PORT=5432
export POSTGRES_DB=marketing
export POSTGRES_USER=username
export POSTGRES_PASSWORD=password
export DATABASE_URL=postgres://username:password@localhost:5432/marketing
Then do
source .myfilename
I came across same issue recently. Your DATABSE_URL
env variable in file .local/.postgres needs to be :
DATABASE_URL=postgres://username:password@{DB_SERVICE_NAME}:5432/marketing
As you can see here in place of localhost use "postgres" if your docker-compose.yml has service name as postgres.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With