From e9a9663887301891992095e267a9d7d11129e399 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 20 Oct 2015 23:05:07 +0200 Subject: [PATCH] Fix database settings This solution makes both Heroku and the dev env happy --- duckbook/settings.py | 23 ++++++----------------- requirements.txt | 1 + 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/duckbook/settings.py b/duckbook/settings.py index ff4cded..741ab53 100644 --- a/duckbook/settings.py +++ b/duckbook/settings.py @@ -10,12 +10,10 @@ https://docs.djangoproject.com/en/1.7/ref/settings/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os +import dj_database_url + BASE_DIR = os.path.dirname(os.path.dirname(__file__)) - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ - # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '-j$x6v))e4=6qy0vm@!@z7-y3k18s2d2j1r&*06x9%rmm$0w1s' @@ -61,19 +59,10 @@ WSGI_APPLICATION = 'duckbook.wsgi.application' # Database # https://docs.djangoproject.com/en/1.7/ref/settings/#databases -try: - import dj_database_url - - DATABASES = { - 'default': dj_database_url.config() - } -except ImportError: - DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } - } +os.environ.setdefault('DATABASE_URL', 'sqlite://' + os.path.join(BASE_DIR, 'db.sqlite3') +DATABASES = { + 'default': dj_database_url.config() +} # Internationalization # https://docs.djangoproject.com/en/1.7/topics/i18n/ diff --git a/requirements.txt b/requirements.txt index 2a52373..42d21fd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ djangorestframework==3.2.4 fuzzywuzzy==0.4.0 python-Levenshtein==0.12.0 gunicorn==19.3.0 +dj-database-url==0.3.0