Adding a new database connection

 Using IDLE or another IDE, open settings.py from the chapter12 project folder. Scroll down to the variable called DATABASES. This variable, which is set to a local SQLite database, will be adjusted to the PostgreSQL database with the PostGIS extension.

This is the default:

DATABASES = {     'default': {         'ENGINE': 'django.db.backends.sqlite3',         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),     }}

Change it to the following, substituting the username and password for your PostGIS installation (see Chapter 3, Introduction to Geospatial Databases):

DATABASES = {    'default': {         'ENGINE': 'django.contrib.gis.db.backends.postgis',         'NAME': 'chapter12',         'USER': '{username}',         'PASSWORD': '{password}',         'HOST': '127.0.0.1', 'PORT':'5432' ...

Get Mastering Geospatial Analysis with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.