mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-08-10 06:54:52 +03:00
Try POSTGRES_ vars when DATABASE_URL is improperly configured
This commit is contained in:
parent
8324c160e8
commit
77a974d88d
|
@ -44,16 +44,28 @@ LOCALE_PATHS = [str(BASE_DIR / "locale")]
|
||||||
# DATABASES
|
# DATABASES
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
||||||
{% if cookiecutter.use_docker == "y" -%}
|
try:
|
||||||
DATABASES = {"default": env.db("DATABASE_URL")}
|
{ % if cookiecutter.use_docker == "y" - %}
|
||||||
{%- else %}
|
DATABASES = {"default": env.db("DATABASE_URL")}
|
||||||
DATABASES = {
|
{ % - else %}
|
||||||
"default": env.db(
|
DATABASES = {
|
||||||
"DATABASE_URL",
|
"default": env.db(
|
||||||
default="postgres://{% if cookiecutter.windows == 'y' %}localhost{% endif %}/{{cookiecutter.project_slug}}",
|
"DATABASE_URL",
|
||||||
),
|
default="postgres://{% if cookiecutter.windows == 'y' %}localhost{% endif %}/{{cookiecutter.project_slug}}",
|
||||||
}
|
),
|
||||||
{%- endif %}
|
}
|
||||||
|
{ % - 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
|
DATABASES["default"]["ATOMIC_REQUESTS"] = True
|
||||||
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
|
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
|
||||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user