How to access a geometry (point) field in PostGIS database from Django?

后端 未结 1 1201
一向
一向 2020-12-11 11:05

In my project I am using PostgreSQL/PostGIS as the database and Django with django.contrib.gis configured. The existing table pois contains geo

相关标签:
1条回答
  • 2020-12-11 11:27

    The database configuration in settings.py was incorrect:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'geodjango',
            'USER': 'geo',
            'PASSWORD': 'secret',
            'HOST': 'localhost',
            'PORT': '5432',
        }
    }
    

    Correct:

    DATABASES = {
        'default': {
            'ENGINE': 'django.contrib.gis.db.backends.postgis', # Here
            'NAME': 'geodjango',
            'USER': 'geo',
            'PASSWORD': 'secret',
            'HOST': 'localhost',
            'PORT': '5432',
        }
    }
    

    I have overseen this in the documentation somehow. Thanks to apollo13 from the #django irc channel for the advice into the right direction.

    0 讨论(0)
提交回复
热议问题