Updated settings to use different dotenv package

This commit is contained in:
Ceferino Patino 2022-08-08 15:13:31 -05:00
commit 3232b86f10
4 changed files with 20 additions and 13 deletions

View file

@ -1,6 +1,7 @@
from pathlib import Path
import os
from django.contrib.messages import constants
from dotenv import dotenv_values
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent.parent
@ -11,7 +12,8 @@ BASE_DIR = Path(__file__).resolve().parent.parent.parent
# SECURITY WARNING: keep the secret key used in production secret!
DOTENV_FILE = BASE_DIR / '.env'
SECRET_KEY = os.environ.get('SECRET_KEY')
CONFIG = dotenv_values(DOTENV_FILE)
SECRET_KEY = CONFIG.get('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
@ -78,8 +80,8 @@ DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dev',
'USER': os.environ.get('DATABASE_USERNAME'),
'PASSWORD': os.environ.get('DATABASE_PASSWORD'),
'USER': CONFIG.get('DATABASE_USERNAME'),
'PASSWORD': CONFIG.get('DATABASE_PASSWORD'),
'HOST': 'mysqldb',
'PORT': '3306'
}

View file

@ -1,6 +1,7 @@
from pathlib import Path
import os
from django.contrib.messages import constants
from dotenv import dotenv_values
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent.parent
@ -11,7 +12,8 @@ BASE_DIR = Path(__file__).resolve().parent.parent.parent
# SECURITY WARNING: keep the secret key used in production secret!
DOTENV_FILE = BASE_DIR / '.env'
SECRET_KEY = os.environ.get('SECRET_KEY')
CONFIG = dotenv_values(DOTENV_FILE)
SECRET_KEY = CONFIG.get('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
@ -21,8 +23,8 @@ SESSION_COOKIE_SECURE = False
CSRF_COOKIE_SECURE = False
ALLOWED_HOSTS = [
'localhost',
'127.0.0.1',
'45.79.52.230',
'housewars.c4thebomb101.com'
]
# Application definition
@ -77,10 +79,10 @@ WSGI_APPLICATION = 'CollegiateHouseWars.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'prod',
'USER': os.environ.get('DATABASE_USERNAME'),
'PASSWORD': os.environ.get('DATABASE_PASSWORD'),
'HOST': 'mysqldb',
'NAME': 'housewars',
'USER': CONFIG.get('DATABASE_USERNAME'),
'PASSWORD': CONFIG.get('DATABASE_PASSWORD'),
'HOST': 'localhost',
'PORT': '3306'
}
}
@ -121,7 +123,7 @@ USE_TZ = True
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = 'static/'
STATIC_ROOT = '/var/www/housewars/static/'
STATIC_ROOT = '/var/www/housewars/files/static/'
STATICFILES_DIRS = [
BASE_DIR / "static"

View file

@ -1,6 +1,7 @@
from pathlib import Path
import os
from django.contrib.messages import constants
from dotenv import dotenv_values
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent.parent
@ -10,7 +11,8 @@ BASE_DIR = Path(__file__).resolve().parent.parent.parent
# SECURITY WARNING: keep the secret key used in production secret!
DOTENV_FILE = BASE_DIR / '.env'
SECRET_KEY = os.environ.get('SECRET_KEY')
CONFIG = dotenv_values(DOTENV_FILE)
SECRET_KEY = CONFIG.get('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

View file

@ -11,6 +11,7 @@ import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CollegiateHouseWars.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
'CollegiateHouseWars.settings.prod')
application = get_wsgi_application()