From 2040e435850dca677312ba20473614ee3271da3f Mon Sep 17 00:00:00 2001 From: behruz-dev Date: Mon, 14 Jul 2025 14:47:27 +0500 Subject: [PATCH] cofigurate settings --- .dockerignore | 1 + config/conf/__init__.py | 0 config/env.py | 18 +++++++++++++++++ config/settings/base.py | 42 ++++++++++++++++++++++++++-------------- config/settings/local.py | 1 + config/settings/prod.py | 1 + requirements.txt | 3 ++- 7 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 config/conf/__init__.py create mode 100644 config/env.py diff --git a/.dockerignore b/.dockerignore index e69de29..5ceb386 100644 --- a/.dockerignore +++ b/.dockerignore @@ -0,0 +1 @@ +venv diff --git a/config/conf/__init__.py b/config/conf/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config/env.py b/config/env.py new file mode 100644 index 0000000..bd861c9 --- /dev/null +++ b/config/env.py @@ -0,0 +1,18 @@ +import os + +import environ + +environ.Env.read_env(os.path.join('.env')) + + +env = environ.Env( + DB_ENGINE=(str, 'django.db.backends.postgresql'), + DB_NAME=(str), + DB_USER=(str, 'postgres'), + DB_PASSWORD=(str), + DB_HOST=(str, 'localhost'), + DB_PORT=(int, 5432), + DEBUG=(bool, False), + ALLOWED_HOSTS=(list, ['localhost', '127.0.0.1']), + SECRET_KEY=(str) +) \ No newline at end of file diff --git a/config/settings/base.py b/config/settings/base.py index 7c7dd97..6ccd804 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -1,5 +1,6 @@ from pathlib import Path +from config.env import env # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent.parent @@ -8,17 +9,16 @@ BASE_DIR = Path(__file__).resolve().parent.parent.parent # See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-p4ybgfc_5v7@l8ocv9$8%i!(kn2ey$@l#k6rg=fux-n41!(3&e' +SECRET_KEY = env.str('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = env.bool("DEBUG") -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = env.list('ALLOWED_HOSTS') # Application definition - -INSTALLED_APPS = [ +DJANGO_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -27,6 +27,22 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', ] +APPS = [ + 'core.apps.shared', + 'core.apps.accounts', + 'core.apps.contracts', +] + +PACKAGES = [ + +] + +INSTALLED_APPS = [] +INSTALLED_APPS += DJANGO_APPS +INSTALLED_APPS += PACKAGES +INSTALLED_APPS += APPS + + MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -55,26 +71,24 @@ TEMPLATES = [ ] WSGI_APPLICATION = 'config.wsgi.application' - +ASGI_APPLICATION = 'config.asgi.application' # Database # https://docs.djangoproject.com/en/5.2/ref/settings/#databases - DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'trustme_db', - 'USER': 'postgres', - 'PASSWORD': '20090912', - 'HOST': 'db', - 'PORT': 5432, + 'ENGINE': env.str('DB_ENGINE'), + 'NAME': env.str('DB_NAME'), + 'USER': env.str('DB_USER'), + 'PASSWORD': env.str('DB_PASSWORD'), + 'HOST': env.str('DB_HOST'), + 'PORT': env.int('DB_PORT'), } } # Password validation # https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators - AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', diff --git a/config/settings/local.py b/config/settings/local.py index e69de29..8e752b2 100644 --- a/config/settings/local.py +++ b/config/settings/local.py @@ -0,0 +1 @@ +from config.settings.base import * \ No newline at end of file diff --git a/config/settings/prod.py b/config/settings/prod.py index e69de29..8e752b2 100644 --- a/config/settings/prod.py +++ b/config/settings/prod.py @@ -0,0 +1 @@ +from config.settings.base import * \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index f0b0bd5..6b13ab1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ django==5.2 gunicorn uvicorn -psycopg2 \ No newline at end of file +psycopg2 +django-environ==0.12.0 \ No newline at end of file