Skip to content

Commit

Permalink
Add requirements dotenv
Browse files Browse the repository at this point in the history
  • Loading branch information
cxrxixs committed May 11, 2024
1 parent ee03b16 commit 55da2b2
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ djlint = "==1.34.1"
pytest = "==8.2.0"
pytest-dotenv = "*"
pytest-django = "*"
python-dotenv = "*"
django-environ = "*"

[packages]
pip = "24.0"
Expand Down
12 changes: 10 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 32 additions & 13 deletions core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,43 @@
"""

import os
import dotenv
import environ

from pathlib import Path


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = (
"django-insecure-()1g-vdgnkjvdhh-621qk*x%^gb&gyh+=s7^f()eghgm7@qo^n"
)
dotenv_file = os.path.join(BASE_DIR, "docker/.env")
if os.path.isfile(dotenv_file):
dotenv.load_dotenv(dotenv_file)
env = environ.Env(
DEBUG=(bool, True),
)
environ.Env.read_env()
DEBUG = env("DEBUG")
SECRET_KEY = env("SECRET_KEY")
DB_NAME = env("DB_NAME")
DB_HOST = env("DB_HOST")
DB_PORT = env("DB_PORT")
DB_USER = env("DB_USER")
DB_PASSWORD = env("DB_PASSWORD")
REDIS_HOST = env("REDIS_HOST")
REDIS_PORT = env("REDIS_PORT")
else:
DB_NAME = os.environ.get("DB_NAME")
DB_USER = os.environ.get("DB_USER")
DB_PASSWORD = os.environ.get("DB_PASSWORD")
DB_HOST = os.environ.get("DB_HOST")
DB_PORT = os.environ.get("DB_PORT")
REDIS_HOST = os.environ.get("REDIS_HOST")
REDIS_PORT = os.environ.get("REDIS_PORT")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv("DEBUG", False)

ALLOWED_HOSTS = ["localhost", "127.0.0.1"]

Expand Down Expand Up @@ -89,11 +108,11 @@
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ.get("DB_NAME"),
"USER": os.environ.get("DB_USER"),
"PASSWORD": os.environ.get("DB_PASSWORD"),
"HOST": os.environ.get("DB_HOST"),
"PORT": os.environ.get("DB_PORT"),
"NAME": DB_NAME,
"USER": DB_USER,
"PASSWORD": DB_PASSWORD,
"HOST": DB_HOST,
"PORT": DB_PORT,
}
}

Expand All @@ -120,7 +139,7 @@
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": f"redis://{os.environ.get('REDIS_HOST')}:{os.environ.get('REDIS_PORT')}/1",
"LOCATION": f"redis://{REDIS_HOST}:{REDIS_PORT}/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
Expand Down
1 change: 1 addition & 0 deletions docker/.env.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DJANGO_SETTINGS_MODULE=app.settings.local
SECRET_KEY=notsafesecret
DB_NAME=db_dev
DB_USER=dev
DB_PASSWORD=S@mEP455w0rd
Expand Down
4 changes: 3 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Django==4.2.11
psycopg2==2.9.9
django-environ==0.11.2
django-redis==5.4.0
psycopg2==2.9.9
python-dotenv==1.0.1

0 comments on commit 55da2b2

Please sign in to comment.