'Determine the version of the PostGIS library.'

@cached_property
def spatial_version(self):

    if hasattr(settings, 'POSTGIS_VERSION'):
        version = settings.POSTGIS_VERSION
    else:
        self._get_postgis_func('version')
        try:
            vtup = self.postgis_version_tuple()
        except ProgrammingError:
            raise ImproperlyConfigured(('Cannot    determine    PostGIS    version    for    database    "%s"    using    command    "SELECT    postgis_lib_version()".    GeoDjango    requires    at    least    PostGIS    version    2.1.    Was    the    database    created    from    a    spatial    database    template?' % self.connection.settings_dict['NAME']))
        version = vtup[1:]
    return version
