Browse Source

Fix database config

pull/2/merge
Rodolfo Carvalho 10 years ago
parent
commit
fcf0ccde53
3 changed files with 28 additions and 9 deletions
  1. +10
    -2
      application-template.json
  2. +18
    -6
      project/settings.py
  3. +0
    -1
      requirements.txt

+ 10
- 2
application-template.json View File

@ -173,8 +173,16 @@
"value": "${DJANGO_SECRET_KEY}" "value": "${DJANGO_SECRET_KEY}"
}, },
{ {
"name": "DATABASE_URL",
"value": "postgres://${DATABASE_USER}:${DATABASE_PASSWORD}@$DATABASE_SERVICE_HOST:$DATABASE_SERVICE_PORT/${DATABASE_NAME}"
"name": "DATABASE_USER",
"value": "${DATABASE_USER}"
},
{
"name": "DATABASE_PASSWORD",
"value": "${DATABASE_PASSWORD}"
},
{
"name": "DATABASE_NAME",
"value": "${DATABASE_NAME}"
} }
] ]
} }


+ 18
- 6
project/settings.py View File

@ -12,7 +12,6 @@ https://docs.djangoproject.com/en/1.8/ref/settings/
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os import os
import dj_database_url
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -80,11 +79,24 @@ WSGI_APPLICATION = 'project.wsgi.application'
# Database # Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases # https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': dj_database_url.config(
default='sqlite:///'+os.path.join(BASE_DIR, 'db.sqlite3')
)
}
if os.getenv("DATABASE_SERVICE_HOST"):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.getenv("DATABASE_NAME"),
'USER': os.getenv("DATABASE_USER"),
'PASSWORD': os.getenv("DATABASE_PASSWORD"),
'HOST': os.getenv("DATABASE_SERVICE_HOST"),
'PORT': os.getenv("DATABASE_SERVICE_PORT"),
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization # Internationalization


+ 0
- 1
requirements.txt View File

@ -2,4 +2,3 @@ Django==1.8.1
psycopg2==2.6 psycopg2==2.6
gunicorn==19.3.0 gunicorn==19.3.0
whitenoise==1.0.6 whitenoise==1.0.6
dj-database-url==0.3.0

Loading…
Cancel
Save