The open blogging platform. Say no to algorithms and paywalls.

Building Dynamic Web Apps: A Step-by-Step Guide to Supabase and Django Integration

A guide to building dynamic web apps with Django and Supabase.

In today’s fast-paced digital landscape, building and scaling web applications efficiently and cost-effectively is paramount. One emerging solution that’s been gaining significant attention is Supabase — a dynamic platform that combines the robustness of PostgreSQL databases with the ease of use and scalability of a serverless architecture. Whether you’re a seasoned developer or just starting your journey, Supabase offers a compelling entry point into the world of database management, starting with a free tier and scaling to meet the needs of your growing application.

Install dependencies

pip install psycopg2-binary

Create database

Copy credentials

Setup credentials in Django

Go to settings.py and update your credentials.

DATABASES = {  
    'default': {  
        'ENGINE': 'django.db.backends.postgresql_psycopg2',  
        'HOST': 'db.fckfkkmbqviwtndzupys.supabase.co',  
        'NAME': 'postgres',  
        'USER': 'postgres',  
        'PORT': '5432',  
        'PASSWORD': 'zwhLYqECWiHcqcYd',  
    }  
}

Custom model (optional)

If you want to your setup in models.py your own model.

from django.db import models  

# Create your models here.  
  
  
class Todo(models.Model):  
    label = models.CharField(max_length=255)  
    description = models.CharField(max_length=255)  
  
    def __str__(self):  
        return f"{self.label}"

Run migrations

To create our table with a Django-prepared tables, we need to run migrations.

python manage.py makemigrations [your-app]  
python manage.py migrate 

You should see this output in the console.

Now in the database we have newly created tables.

Good job! That's it. Now the database is ready.


Thanks for reading my article!

If you enjoyed the read and want to be part of our growing community, hit the follow button, and let’s embark on a knowledge journey together.




Continue Learning