Try POSTGRES_ vars when DATABASE_URL is improperly configured

This commit is contained in:
Jelmer Draaijer 2024-01-27 12:23:15 +01:00
parent 8324c160e8
commit 77a974d88d

View File

@ -44,6 +44,7 @@ LOCALE_PATHS = [str(BASE_DIR / "locale")]
# DATABASES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
try:
{ % if cookiecutter.use_docker == "y" - %}
DATABASES = {"default": env.db("DATABASE_URL")}
{ % - else %}
@ -54,6 +55,17 @@ DATABASES = {
),
}
{ % - endif %}
except environ.ImproperlyConfigured:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": env.str("POSTGRES_DB"),
"USER": env.str("POSTGRES_USER"),
"PASSWORD": env.str("POSTGRES_PASSWORD"),
"HOST": env.str("POSTGRES_HOST"),
"PORT": env.str("POSTGRES_PORT"),
}
}
DATABASES["default"]["ATOMIC_REQUESTS"] = True
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"