Cain Manor

Your Guide To All Things Cain™

Install Django on OS-X Snow Leopard using sqlite3

Down­load django.   It should default to your ~/Downloads folder and it should be untarred. Go into that direc­tory (in my case, /Users/gregcain/Downloads/Django-1.2.4), and install Django.

sudo python setup.py install


Now we need to con­fig­ure our first project, which we’ll call myBooks. Cre­ate the par­ent direc­tory you want your project to live in.

mkdir ~/Django

Let’s cre­ate the first project

django-admin.py startproject myBooks

You’ll see a direc­tory cre­ated under­neath your Django direc­tory called myBooks. (~/Django/myBooks) In that direc­tory, you’ll see the fol­low­ing files…

__init__.py
manage.py
settings.py
urls.py

Start the built in web server. From the direc­tory ~/Django/myBooks directory

python manage.py runserver

Which gives you this..

Django version 1.2.4, using settings 'myBooks.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

If you point your web browser to http://127.0.0.1:8000/ you should see this basic get­ting started page

If you see that, all is good so far…

Now let’s con­fig­ure Django to use sqlite as it’s data­base. All you need to do is edit the settings.py file in ~/Django/myBooks. You need to change ENGINE to the sqlite3 instance, and tell it where you want your data­base to live. You’ll cre­ate that data­base in the next step.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '/Users/gregcain/Django/myBooks/myBooksDB',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

Now cre­ate the database

python manage.py syncdb

You’ll be asked a few ques­tions, includ­ing one to setup a super user.

Now that the data­base is cre­ated, let’s go in and see if it looks cor­rect. To open a con­nec­tion to the database

sqlite3 myBooksDB

and to see the schema

.schema

Happy Cod­ing!!

Comments are closed.