This is a continuation of the series of posts on my workflow with Django. I am writing as a means of documenting my work, but feel free to follow it you find it helpful.

This is loosely based on the Django tutorial from here. This tutorial uses the 1.5 version of Django.

Project setup

Let's set up a Django project!

Creating a project

To create a project, use the following command django-admin.py startproject myproject.

This will create a starter project with the following structure:

myproject/
    manage.py
    myproject/
        __init__.py
        settings.py
        urls.py
        wsgi.py

Database settings

Now, if you change to the directory that contains the settings.py file, you can change your projects settings. Here you can specify the database engine you will be using (SQLite, PostgreSQL or MySQL) and enter the database credentials (if applicable).

The following is an excerpt of settings.py:

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql_psycopg2", # Add "postgresql_psycopg2", "mysql", "sqlite3" or "oracle".
        "NAME": "MY_DATABASE_NAME",                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        "USER": "MY_DATABASE_USER",
        "PASSWORD": "MY_DATABASE_PASSWORD",
        "HOST": "",                      # Empty for localhost through domain sockets or "127.0.0.1" for localhost through TCP.
        "PORT": "",                      # Set to empty string for default.
    }
}

I changed the engine to be django.db.backends.postgresql_psycopg2 as I will be using PostgreSQL. I already created the database so I added the database name, user, and password also.

If you are going to be using any other database or need more information, refer to the Django documentation.

Sync database

To sync the database to create the database tables, use this command python manage.py syncdb.

This will create the database tables for the installed apps that you have enabled in your settings.py file.

Get to work!

The project is now set up. You can continue now by creating an app.