From 4591ce8d7dff8bf20df00993944333c6487912e8 Mon Sep 17 00:00:00 2001 From: Jerrica Bobadilla Date: Thu, 8 Oct 2020 11:30:03 -0700 Subject: [PATCH] configure env --- .env.sample | 1 + Pipfile | 2 ++ Pipfile.lock | 18 +++++++++++++++++- django_contacts/settings.py | 19 +++++++++++++++---- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.env.sample b/.env.sample index e69de29..2289c98 100644 --- a/.env.sample +++ b/.env.sample @@ -0,0 +1 @@ +SECRET_KEY=putsomesecrethere \ No newline at end of file diff --git a/Pipfile b/Pipfile index c9803e2..7c9a7a0 100644 --- a/Pipfile +++ b/Pipfile @@ -9,6 +9,8 @@ verify_ssl = true django = "*" psycopg2-binary = "*" django-extensions = "*" +python-dotenv = "*" +dj-database-url = "*" [requires] python_version = "3.8" diff --git a/Pipfile.lock b/Pipfile.lock index ee0359e..26945b7 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "787971d93a72d315fb906991a877356e209592be55f6f0fa79f09bc68e93848b" + "sha256": "33ea631283b8f623ef5e8f5c404c4bb26e1735f210ae464284563318405b30f3" }, "pipfile-spec": 6, "requires": { @@ -24,6 +24,14 @@ "markers": "python_version >= '3.5'", "version": "==3.2.10" }, + "dj-database-url": { + "hashes": [ + "sha256:4aeaeb1f573c74835b0686a2b46b85990571159ffc21aa57ecd4d1e1cb334163", + "sha256:851785365761ebe4994a921b433062309eb882fedd318e1b0fcecc607ed02da9" + ], + "index": "pypi", + "version": "==0.5.0" + }, "django": { "hashes": [ "sha256:a2127ad0150ec6966655bedf15dbbff9697cc86d61653db2da1afa506c0b04cc", @@ -78,6 +86,14 @@ "index": "pypi", "version": "==2.8.6" }, + "python-dotenv": { + "hashes": [ + "sha256:8c10c99a1b25d9a68058a1ad6f90381a62ba68230ca93966882a4dbc3bc9c33d", + "sha256:c10863aee750ad720f4f43436565e4c1698798d763b63234fb5021b6c616e423" + ], + "index": "pypi", + "version": "==0.14.0" + }, "pytz": { "hashes": [ "sha256:a494d53b6d39c3c6e44c3bec237336e14305e4f29bbf800b599253057fbb79ed", diff --git a/django_contacts/settings.py b/django_contacts/settings.py index b25e3fc..b01d856 100644 --- a/django_contacts/settings.py +++ b/django_contacts/settings.py @@ -10,22 +10,29 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.1/ref/settings/ """ +import os +import dj_database_url + from pathlib import Path -# Build paths inside the project like this: BASE_DIR / 'subdir'. -BASE_DIR = Path(__file__).resolve().parent.parent +# .env config +from dotenv import load_dotenv, find_dotenv +load_dotenv(find_dotenv()) + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'n6&$_khrc&w%r&ufg$qmat915-4uhnoux)-_nttj&-0sxpn#dh' +SECRET_KEY = os.environ['SECRET_KEY'] # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['localhost'] # Application definition @@ -85,6 +92,9 @@ DATABASES = { } } +# Updating database when deployed +db_from_env = dj_database_url.config(conn_max_age=600) +DATABASES['default'].update(db_from_env) # Password validation # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators @@ -123,3 +133,4 @@ USE_TZ = True # https://docs.djangoproject.com/en/3.1/howto/static-files/ STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') \ No newline at end of file