forked from rhouben/pda-next
Proper .env loading and a working .gitignore
This commit is contained in:
@@ -10,22 +10,18 @@ For the full list of settings and their values, see
|
|||||||
https://docs.djangoproject.com/en/5.2/ref/settings/
|
https://docs.djangoproject.com/en/5.2/ref/settings/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
load_dotenv(BASE_DIR / ".env")
|
load_dotenv(BASE_DIR / ".env")
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
|
||||||
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
|
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
|
||||||
SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]
|
SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
|
||||||
DEBUG = int(os.environ.get("DJANGO_DEBUG", default=0))
|
DEBUG = int(os.environ.get("DJANGO_DEBUG", default=0))
|
||||||
|
|
||||||
ALLOWED_HOSTS = os.environ.get(
|
ALLOWED_HOSTS = os.environ.get(
|
||||||
"DJANGO_ALLOWED_HOSTS", default="localhost 127.0.0.1 0.0.0.0"
|
"DJANGO_ALLOWED_HOSTS", default="localhost 127.0.0.1 0.0.0.0"
|
||||||
).split()
|
).split()
|
||||||
@@ -71,18 +67,26 @@ TEMPLATES = [
|
|||||||
|
|
||||||
WSGI_APPLICATION = "config.wsgi.application"
|
WSGI_APPLICATION = "config.wsgi.application"
|
||||||
|
|
||||||
|
DB_ENGINE=os.environ.get('DB_ENGINE', default='sqlite3')
|
||||||
# Database
|
DEFAULT_DB = {
|
||||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
'ENGINE': 'django.db.backends.%s' % DB_ENGINE,
|
||||||
|
}
|
||||||
|
if DB_ENGINE=='sqlite3':
|
||||||
|
DEFAULT_DB['NAME'] = os.path.join('BASE_DIR', os.environ.get('DB_NAME', default='urania.sqlite3'))
|
||||||
|
else:
|
||||||
|
DEFAULT_DB['NAME'] = os.environ.get('DB_NAME')
|
||||||
|
DEFAULT_DB['USER'] = os.environ.get('DB_USER')
|
||||||
|
DEFAULT_DB['PASSWORD'] = os.environ.get('DB_PASSWORD')
|
||||||
|
DEFAULT_DB['HOST'] = os.environ.get('DB_HOST')
|
||||||
|
if DB_ENGINE=='postgresql':
|
||||||
|
DEFAULT_DB['PORT'] = os.environ.get('DB_PORT', default=5432)
|
||||||
|
elif DB_ENGINE=='mysql':
|
||||||
|
DEFAULT_DB['PORT'] = os.environ.get('DB_PORT', default=3306)
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
"default": {
|
'default': DEFAULT_DB,
|
||||||
"ENGINE": "django.db.backends.sqlite3",
|
|
||||||
"NAME": BASE_DIR / "db.sqlite3",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user