From c9df5bbb75e4e727113782594b75f8ed5c6a54b9 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Wed, 15 May 2024 11:48:20 +0200 Subject: [PATCH] Add check if .env file exists before loading it --- greenweb/settings/common.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/greenweb/settings/common.py b/greenweb/settings/common.py index 84305c20..fd15c5a3 100644 --- a/greenweb/settings/common.py +++ b/greenweb/settings/common.py @@ -42,7 +42,13 @@ ), ) -environ.Env.read_env(".env") # Read .env +# in some cases we don't have a .env file to work from - the environment +# variables are provided via docker for example. So, we only try to load the +# .env file if it exists. +dotenv_file = pathlib.Path(ROOT) / ".env" +if dotenv_file.exists(): + environ.Env.read_env(".env") + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/