Reputation: 41
cookiecutter-django does not set env variables for DATABASE_URL and CELERY_BROKER_URL during "entrypoint" file execution in local development environment.
After I manually 'exported' DATABASE_URL and CELERY_BROKER_URL they appeared in environment variables. Why is that?
By manually I mean I got inside the docker container then on the shell I wrote:
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
and
export CELERY_BROKER_URL="${REDIS_URL}"
Upvotes: 4
Views: 895
Reputation: 346
Following the answer in this post I ended up adding:
DATABASE_URL=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB
to my <project_slug>\.envs\.local\.postgres
file.
This does not Answer the user's question: "Why does Cookiecutter not set this at creation?". It is the solution to my problem that lead me to this post.
Should I have added this to my .envs? Is it bad practice? It fixed an error "Set the DATABASE_URL environment variable" that happened after I dropped the volumes and went to recreate the superuser in a blank DB.
Upvotes: -1
Reputation: 1463
It might be because the environment variable DJANGO_READ_DOT_ENV_FILE
is set to False
by default. Set it to True
in your runtime environment and it will start reading the .env
file and the DATABASE_URL
in it:
export DJANGO_READ_DOT_ENV_FILE=True
Upvotes: 0