feat: configure environment variables, CORS, and PostgreSQL database settings for backend-frontend integration

This commit is contained in:
Your Name
2026-04-09 12:39:42 +05:30
parent 17b8356eac
commit 4bdb1ee80d
2 changed files with 20 additions and 4 deletions
+18 -4
View File
@@ -10,20 +10,25 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/6.0/ref/settings/
"""
import os
from pathlib import Path
import environ
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
env = environ.Env()
# find .env in root
environ.Env.read_env(os.path.join(BASE_DIR.parent, ".env"))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-rj_!92m9m5o7&&g5q=uj#=+7@h6q16o4l-7^u2ilz014j%oo-t"
SECRET_KEY = env("SECRET_KEY")
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = env("DEBUG")
ALLOWED_HOSTS = []
@@ -37,9 +42,12 @@ INSTALLED_APPS = [
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"rest_framework", # for API
"corsheaders", # for API and Frontend connect
]
MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware", # allow frontend to connect
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
@@ -74,11 +82,17 @@ WSGI_APPLICATION = "config.wsgi.application"
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
"ENGINE": "django.db.backends.postgresql",
"NAME": env("DB_NAME"),
"USER": env("DB_USER"),
"PASSWORD": env("DB_PASSWORD"),
"HOST": env("DB_HOST"),
"PORT": env("DB_PORT"),
}
}
CORS_ALLOWED_ORIGINS = env.list("CORS_ALLOWED_ORIGINS")
# Password validation
# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators