Skip to content

Commit 0909fab

Browse files
Add database env variable
1 parent 1049855 commit 0909fab

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

django_blog/settings.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212

1313
import os
1414
import json
15-
import django_heroku
15+
import dj_database_url
16+
17+
from dotenv import load_dotenv
1618

1719
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
1820
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1921

20-
22+
load_dotenv(BASE_DIR / '.env')
2123
# Quick-start development settings - unsuitable for production
2224
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
2325

@@ -27,7 +29,7 @@
2729
# SECURITY WARNING: don't run with debug turned on in production!
2830
DEBUG = os.environ.get('PRODUCTION') != 'true'
2931

30-
ALLOWED_HOSTS = ['localhost', 'https://django-blog-7rxa.onrender.com/']
32+
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS').split(' ')
3133

3234

3335
# Application definition
@@ -79,10 +81,7 @@
7981
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
8082

8183
DATABASES = {
82-
'default': {
83-
'ENGINE': 'django.db.backends.sqlite3',
84-
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
85-
}
84+
'default': dj_database_url.parse(os.environ.get('DATABASE_URL'), conn_max_age=600)
8685
}
8786

8887

@@ -144,5 +143,3 @@
144143
EMAIL_HOST_USER = os.environ.get('EMAIL_USER')
145144
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASS')
146145
DEFAULT_FROM_EMAIL = 'CodingWithAndrewTeam <noreply@codingwithandrew.com>'
147-
148-
django_heroku.settings(locals())

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ django-heroku==0.3.1
88
gunicorn==20.0.4
99
idna==2.10
1010
Pillow==7.2.0
11-
psycopg2==2.7.5
12-
psycopg2-binary==2.8.6
11+
psycopg2==2.9.5
12+
psycopg2-binary==2.9.5
13+
python-dotenv==0.21.1
1314
pytz==2020.1
1415
requests==2.24.0
1516
sqlparse==0.3.1

0 commit comments

Comments
 (0)