From 3c3f9ee98be0034fbb8557401d000c2bbfaddd17 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 2 Mar 2019 16:49:58 +0100 Subject: [PATCH] Add django-heroku config --- Pipfile | 2 +- Pipfile.lock | 18 ++++++++++++++++-- friends_map/settings.py | 23 ++++++++++++++++++++--- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Pipfile b/Pipfile index 7493e81..f31bf3c 100644 --- a/Pipfile +++ b/Pipfile @@ -7,9 +7,9 @@ name = "pypi" django = "*" gitpython = "*" django-crispy-forms = "*" -dj-database-url = "*" "psycopg2" = "*" gunicorn = "*" +django-heroku = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index ac8da66..aac0909 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "8e4f8594bffd8bc27af35d8b7d41c9db598ec2715709e3e11060671d4bdb6a06" + "sha256": "865aaeb0d93d5e877f331fdeeabff95e3ea61ac49c894a62024e039c847c0218" }, "pipfile-spec": 6, "requires": { @@ -21,7 +21,6 @@ "sha256:4aeaeb1f573c74835b0686a2b46b85990571159ffc21aa57ecd4d1e1cb334163", "sha256:851785365761ebe4994a921b433062309eb882fedd318e1b0fcecc607ed02da9" ], - "index": "pypi", "version": "==0.5.0" }, "django": { @@ -40,6 +39,14 @@ "index": "pypi", "version": "==1.7.2" }, + "django-heroku": { + "hashes": [ + "sha256:2bc690aab89eedbe01311752320a9a12e7548e3b0ed102681acc5736a41a4762", + "sha256:6af4bc3ae4a9b55eaad6dbe5164918982d2762661aebc9f83d9fa49f6009514e" + ], + "index": "pypi", + "version": "==0.3.1" + }, "gitdb2": { "hashes": [ "sha256:83361131a1836661a155172932a13c08bda2db3674e4caa32368aa6eb02f38c2", @@ -112,6 +119,13 @@ "sha256:29a9ffa0497e7f2be94ca0ed1ca1aa3cd4cf25a1f6b4f5f87f74b46ed91d609a" ], "version": "==2.0.5" + }, + "whitenoise": { + "hashes": [ + "sha256:118ab3e5f815d380171b100b05b76de2a07612f422368a201a9ffdeefb2251c1", + "sha256:42133ddd5229eeb6a0c9899496bdbe56c292394bf8666da77deeb27454c0456a" + ], + "version": "==4.1.2" } }, "develop": {} diff --git a/friends_map/settings.py b/friends_map/settings.py index 695fb9b..cdc2c48 100644 --- a/friends_map/settings.py +++ b/friends_map/settings.py @@ -13,7 +13,7 @@ https://docs.djangoproject.com/en/2.1/ref/settings/ import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) -import dj_database_url +import django_heroku BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -27,7 +27,18 @@ SECRET_KEY = '(b_w%!e9u!3q=d-u!$g6ntpzh-=4mo$gs#96as+^179vp6stui' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = [ + '.herokuapp.com', +] + +HOST = os.environ.get('HOST') +if HOST: + ALLOWED_HOSTS.append(HOST) + +if DEBUG: + ALLOWED_HOSTS += [ + 'localhost' + ] # Application definition @@ -79,7 +90,12 @@ WSGI_APPLICATION = 'friends_map.wsgi.application' # Database # https://docs.djangoproject.com/en/2.1/ref/settings/#databases -DATABASES = {'default': dj_database_url.config(default=f'sqlite:///{BASE_DIR}/db.sqlite3', conn_max_age=600)} +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} # Password validation @@ -143,3 +159,4 @@ APP = { CRISPY_TEMPLATE_PACK = 'bootstrap4' LOGOUT_REDIRECT_URL = '/' +django_heroku.settings(locals(), allowed_hosts=False, databases=not DEBUG)