Skip to content

Commit

Permalink
Changed settings.py file, moved ENVs to file
Browse files Browse the repository at this point in the history
  • Loading branch information
n8creator committed Dec 13, 2023
1 parent 0a8569c commit e4b7442
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .env-sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DEBUG=True
SECRET_KEY="django-insecure-0g#f&l$r)*)$k)%)qp8jyh_ifkg$x1b%st7@7ni^4gd&3th)d2"
41 changes: 31 additions & 10 deletions task_manager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@
https://docs.djangoproject.com/en/5.0/ref/settings/
"""

import os
from pathlib import Path

import dj_database_url
from dotenv import load_dotenv

# Load ENV variables
load_dotenv()

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

Expand All @@ -20,13 +27,17 @@
# 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-0g#f&l$r)*)$k)%)qp8jyh_ifkg$x1b%st7@7ni^4gd&3th)d2"
SECRET_KEY = os.getenv("SECRET_KEY", "secret_key")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
DEBUG = os.getenv("DEBUG", "False")

ALLOWED_HOSTS = [
"127.0.0.1",
"localhost",
"webserver",
"monet.n8creator.com",
]

# Application definition

Expand Down Expand Up @@ -76,13 +87,23 @@
# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
if DEBUG:
# Use SQLite for local development
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}
else:
# Use PostgreSQL for production on Dokku server
DATABASES = {
"default": dj_database_url.config(
default=os.environ.get("DATABASE_URL"),
conn_max_age=600,
conn_health_checks=True,
),
}
}


# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
Expand Down

0 comments on commit e4b7442

Please sign in to comment.