DJango Notes

Page Contents

Create A Django Project

Creating The Project

Running from the directory in which you want to house your new project that you have named <prj-name>:

django-admin startproject <prj-name>

Creates a new directory named <prj-name> under your CWD:

prj-name
  |
  +-- prj-name/
        |
        +-- urls.py <- The global index mapping views to URLs

Add A New App

From the project directory <prj-name>:

python manage.py startapp <app-name>

This extends the directory structure as follows:

prj-name
  |
  +-- prj-name/
  |     |
  |     +-- urls.py <- The global index mapping views to URLs
  |
  +-- app-name/
        |
        +-- admin.py
        +-- apps.py
        +-- models.py
        +-- tests.py
        +-- views.py
        +-- migrations/
        +-- urls.py

Then modify <prj-name>/<prj-name>/urls.py (the global index) to point at <prj-name>/<app-name>/urls.py.

Running The Development Server

From the project directory <prj-name>:

python manage.py runserver ip-address:port

Database Migrations