Running with Docker Compose

How to set up PostgreSQL connections in Python with psycopg

Want more?

This lesson for enrolled students only. Join the course to unlock it!

You can see the code changes implemented in this lecture below.

If you have purchased the course in a different platform, you still have access to the code changes per lecture here on Teclado. The lecture video and lecture notes remain locked.
Join course for $15

Modified files

pyproject.toml
--- 
+++ 
@@ -9,6 +9,8 @@
 python = "^3.12"
 django = "^5.1.3"
 django-allauth = {extras = ["socialaccount"], version = "^65.2.0"}
+psycopg = "^3.2.3"
+dj-database-url = "^2.3.0"


 [tool.poetry.group.dev.dependencies]
djangocourse/settings.py
--- 
+++ 
@@ -11,6 +11,7 @@
 """

 from pathlib import Path
+import dj_database_url

 # Build paths inside the project like this: BASE_DIR / 'subdir'.
 BASE_DIR = Path(__file__).resolve().parent.parent
@@ -109,10 +110,7 @@
 # https://docs.djangoproject.com/en/5.1/ref/settings/#databases

 DATABASES = {
-    'default': {
-        'ENGINE': 'django.db.backends.sqlite3',
-        'NAME': BASE_DIR / 'db.sqlite3',
-    }
+    'default': dj_database_url.config(conn_max_age=600)
 }

 AUTH_USER_MODEL = "app.UserProfile"