About Creating Spatial Postgres Database
To use spatial features like distance calculation between points with the Postgres database, you need PostGIS extension. It has to be activated for each Postgres database individually. On MacOS, you can install the database management system and extension with Homebrew:
$ brew install postgres
$ brew install postgis
$ brew services start postgres
Create the user and database for a new project and activate the PostGIS extension with these commands:
$ createuser --createdb --password myprojectuser
$ createdb --username=myprojectuser myprojectdb
$ psql myprojectdb
> CREATE EXTENSION postgis;
Then use "django.contrib.gis.db.backends.postgis" as the database backend in your Django project settings:
DATABASES = {
"default": {
"ENGINE": "django.contrib.gis.db.backends.postgis",
"NAME": "myprojectdb",
"USER": "myprojectuser",
"PASSWORD": "secretpassword",
"HOST": "127.0.0.1",
"PORT": "5432",
}
}
Tips and Tricks Programming Dev Ops Databases Django 5.2 Django 4.2 Django 3.2 PostgreSQL PostGIS
Django/Python Consulting
If you have a specific Django challenge or integration you'd like to solve, I'd be happy to help. Book a free 30-minute call to discuss your project, see if we're a good fit, and explore the best approach for your needs. After the call, you'll receive a tailored cost estimate based on what we discuss.
Also by me
Django Messaging
For Django-based social platforms.
Django Paddle Subscriptions
For Django-based SaaS projects.
Django GDPR Cookie Consent
For Django websites that use cookies.