Setting up the GeoDjango project

We now have to create the Django project that will hold the ShapeEditor application. To do this, cd into the directory where you want the project to be placed and type the following:

% django-admin.py startproject geodjango

Note

When you installed Django, it should have placed the django-admin.py program onto your path, so you shouldn't need to tell the computer where this file resides.

All going well, Django will create a directory named geodjango that contains several files. Let's take a closer look at these files:

  • __init__.py

    You should be familiar with this type of file; it simply tells Python that this directory holds a Python package.

  • manage.py

    This Python script is auto-generated by Django. We will use it to start, stop, and configure our geodjango project.

  • settings.py

    This Python module contains various settings for our GeoDjango project. These settings include options for turning debugging on or off, information about which database the Django project will use, where to find the project's URLConf module, and a list of the applications that should be included in the project.

  • urls.py

    This is the URLConf module for the project. It maps incoming URLs to views within the project's applications.

Now that the project has been created, we next need to configure it. To do this, edit the settings.py file. We want to make the following changes to this file:

  1. Tell Django to use the PostGIS database we set up earlier for this project.
  2. Add the GeoDjango application to the project to enable the GeoDjango functionality.

To tell Django to use PostGIS, edit the DATABASES variable to look like the following:

DATABASES = {
    'default': {
        'ENGINE'   : 'django.contrib.gis.db.backends.postgis',
        'NAME'     : 'geodjango',
        'USER'     : '...',
        'PASSWORD' : '...'
    }
}

Make sure you enter the username and password used to access your particular PostgreSQL database.

To enable the GeoDjango functionality, add the following line to the INSTALLED_APPS variable at the bottom of the file:

'django.contrib.gis'

This completes the configuration of our geodjango project.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.47.208