[GIS] GeoDjango application using SpatiaLite database

djangogeodjangopythonspatial-databasespatialite

I want to create a simple GeoDjango app with SpatiaLite database but I have this error at migrate:

django.core.exceptions.ImproperlyConfigured: Unable to load the
SpatiaLite library extensio`.

Here the code :

settings.py

INSTALLED_APPS = [
    ..................
    'django.contrib.gis',
     .............
]

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

Where I went wrong?

Best Answer

You need to install the SQLite spatial extension SpatiaLite:

  • on Debian-based GNU/Linux distributions (es: Debian, Ubuntu, …):

     $ apt install libsqlite3-mod-spatialite
    
  • on macOS using Hoembrew:

      $ brew install spatialite-tools
    

You can find complete example of a map with Geodjango and Spatialite in this article: Maps with Django (part 1): GeoDjango, SpatiaLite and Leaflet

Related Question