Browse Source

Merge pull request #103 from CatalystCode/enhancement/dotenv-support

Enhancement/Add dotenv support
pull/111/head
Hiroki Nakayama 5 years ago
committed by GitHub
parent
commit
2f59060d6d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 23 deletions
  1. 46
      app/app/settings.py
  2. 1
      requirements.txt

46
app/app/settings.py

@ -1,38 +1,38 @@
"""
Django settings for app project.
Generated by 'django-admin startproject' using Django 2.0.5.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
Any setting that is configured via an environment variable may
also be set in a `.env` file in the project base directory.
"""
from os import path
import os
import django_heroku
import dj_database_url
from environs import Env
# Build paths inside the project like this: path.join(BASE_DIR, ...)
BASE_DIR = path.dirname(path.dirname(path.abspath(__file__)))
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
env = Env()
env.read_env(BASE_DIR, recurse=False)
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get(
'SECRET_KEY',
'v8sk33sy82!uw3ty=!jjv5vp7=s2phrzw(m(hrn^f7e_#1h2al')
SECRET_KEY = env('SECRET_KEY',
'v8sk33sy82!uw3ty=!jjv5vp7=s2phrzw(m(hrn^f7e_#1h2al')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
if os.environ.get('DEBUG') == 'False':
DEBUG = False
# DEBUG = bool(os.environ.get('DEBUG', False))
# DEBUG = os.environ.get('DEBUG') == 'TRUE'
DEBUG = env.bool('DEBUG', True)
# ALLOWED_HOSTS = []
@ -73,7 +73,7 @@ ROOT_URLCONF = 'app.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'server/templates')],
'DIRS': [path.join(BASE_DIR, 'server/templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
@ -92,7 +92,7 @@ TEMPLATES = [
]
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'server/static'),
path.join(BASE_DIR, 'server/static'),
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
@ -105,12 +105,12 @@ AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
]
SOCIAL_AUTH_GITHUB_KEY = os.getenv('OAUTH_GITHUB_KEY')
SOCIAL_AUTH_GITHUB_SECRET = os.getenv('OAUTH_GITHUB_SECRET')
SOCIAL_AUTH_GITHUB_KEY = env('OAUTH_GITHUB_KEY', None)
SOCIAL_AUTH_GITHUB_SECRET = env('OAUTH_GITHUB_SECRET', None)
SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_KEY = os.getenv('OAUTH_AAD_KEY')
SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_SECRET = os.getenv('OAUTH_AAD_SECRET')
SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID = os.getenv('OAUTH_AAD_TENANT')
SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_KEY = env('OAUTH_AAD_KEY', None)
SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_SECRET = env('OAUTH_AAD_SECRET', None)
SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID = env('OAUTH_AAD_TENANT', None)
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
@ -118,7 +118,7 @@ SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID = os.getenv('OAUTH_AAD_TENANT')
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'NAME': path.join(BASE_DIR, 'db.sqlite3'),
}
}
@ -195,9 +195,9 @@ SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# on the import phase
IMPORT_BATCH_SIZE = 500
GOOGLE_TRACKING_ID = os.getenv('GOOGLE_TRACKING_ID', 'UA-125643874-2')
GOOGLE_TRACKING_ID = env('GOOGLE_TRACKING_ID', 'UA-125643874-2')
AZURE_APPINSIGHTS_IKEY = os.getenv('AZURE_APPINSIGHTS_IKEY')
AZURE_APPINSIGHTS_IKEY = env('AZURE_APPINSIGHTS_IKEY', None)
APPLICATION_INSIGHTS = {
'ikey': AZURE_APPINSIGHTS_IKEY if AZURE_APPINSIGHTS_IKEY else None,
}

1
requirements.txt

@ -9,6 +9,7 @@ django-rest-polymorphic==0.1.8
djangorestframework==3.8.2
djangorestframework-csv==2.1.0
djangorestframework-filters==0.10.2
environs==4.1.0
djangorestframework-xml==1.4.0
Faker==0.8.8
flake8==3.6.0

Loading…
Cancel
Save