Published: 9 November 2011 | By Rolo Mawlabaux
Installing GeoDjango and PostGIS can be notoriously tricky, especially when versions shift. Here is the step-by-step guide for getting a stable environment running on Ubuntu 11.10 using Postgres 9.1.
Step 1: Prerequisites
Before installing, ensure your package lists are up to date and you have the necessary dependencies for spatial data.
sudo apt-get update
sudo apt-get install binutils libproj-dev gdal-bin libgeos-c1
Step 2: Installing PostGIS
Postgres 9.1 in Ubuntu 11.10 requires the standard core and the postgis extension package.
sudo apt-get install postgresql-9.1-postgis
Step 3: Database Setup
Create your spatial template for your projects.
sudo -u postgres createdb template_postgis
sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql
sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql
You can now use this template for your Django projects:
CREATE DATABASE my_geo_project WITH TEMPLATE template_postgis;
Conclusion
With these steps, your environment should be fully configured for Django's spatial ORM features. Always ensure your DATABASE_ENGINE in settings.py is set to django.contrib.gis.db.backends.postgis.