Skip to content

Commit 27ba6f7

Browse files
author
Steven Normore
committed
Use dj-database-url
1 parent ecc8f8e commit 27ba6f7

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

mysite/settings.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pathlib import Path
1313
import os
1414
import sys
15+
import dj_database_url
1516
from urllib.parse import urlparse
1617

1718
from django.core.management.utils import get_random_secret_key
@@ -89,17 +90,8 @@
8990
elif len(sys.argv) > 0 and sys.argv[1] != 'collectstatic':
9091
if os.getenv("DATABASE_URL", None) is None:
9192
raise Exception("DATABASE_URL environment variable not defined")
92-
r = urlparse(os.environ.get("DATABASE_URL"))
9393
DATABASES = {
94-
"default": {
95-
"ENGINE": "django.db.backends.postgresql_psycopg2",
96-
"NAME": os.path.relpath(r.path, "/"),
97-
"USER": r.username,
98-
"PASSWORD": r.password,
99-
"HOST": r.hostname,
100-
"PORT": r.port,
101-
"OPTIONS": {"sslmode": "require"},
102-
}
94+
"default": dj_database_url.parse(os.environ.get("DATABASE_URL")),
10395
}
10496

10597

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ psycopg2-binary==2.8.6
55
pytz==2020.1
66
sqlparse==0.3.1
77
whitenoise==5.2.0
8+
dj-database-url==0.5.0

0 commit comments

Comments
 (0)