From a82344029f4e5d22b91d2d781b44f7fc00ebea27 Mon Sep 17 00:00:00 2001 From: sosokker Date: Fri, 27 Oct 2023 02:04:13 +0700 Subject: [PATCH] connect with PostgreSQL --- backend/core/settings.py | 15 ++++++++++----- backend/sample.env | 8 ++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 backend/sample.env diff --git a/backend/core/settings.py b/backend/core/settings.py index 9c0d203..b9a05b1 100644 --- a/backend/core/settings.py +++ b/backend/core/settings.py @@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/4.2/ref/settings/ """ from pathlib import Path +from decouple import config, Csv # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -20,12 +21,12 @@ BASE_DIR = Path(__file__).resolve().parent.parent # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-47)&+$r648bswzins@+y)*!qhs2kshz4h09bb5-%zl@yay!n07' +SECRET_KEY = config('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = config('DEBUG', default=False, cast=bool) -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='*', cast=Csv()) # Application definition @@ -94,8 +95,12 @@ WSGI_APPLICATION = 'core.wsgi.application' DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': config('DB_NAME'), + 'USER': config('DB_USER'), + 'PASSWORD': config('DB_PASSWORD'), + 'HOST': config('DB_HOST'), + 'PORT': config('DB_PORT'), } } diff --git a/backend/sample.env b/backend/sample.env new file mode 100644 index 0000000..1b58118 --- /dev/null +++ b/backend/sample.env @@ -0,0 +1,8 @@ +SECRET_KEY=your_secret_key +DEBUG=False +ALLOWED_HOSTS=*.ku.th, localhost, 127.0.0.1, ::1 +DB_NAME=your_DB_NAME +DB_USER=your_DB_USER +DB_PASSWORD=your_DB_PASSWORD +DB_HOST=your_DB_HOST +DB_PORT=your_DB_PORT \ No newline at end of file