From XPUB & Lens-Based wiki

Creating a new Django Project from scratch

Note: this recipe is a shrinked, skimmed, compressed and squeezed version of the official Django tutorial. You should check it first and use this recipe as quick reminder.


This recipes assumes you already have an installed working Apache2 and Django framework.

Start and run a new project

Make a directory that will hold your new Django application and create it.

mkdir ~/Django
cd ~/Django startproject mysite

This creates a folder called mysite that contains the following files:

  • !__init! An empty file that tells Python that this directory should be considered a Python package.
  • A command-line utility that lets you interact with this Django project in various ways.
  • Settings/configuration for this Django project.
  • The URL declarations for this Django project; a "table of contents" of your Django-powered site.

To run the development server and see if your django install is correct, do the following:

cd ~/Django/mysite
./ runserver

Then point your browser to and you should see the message 'It worked! Congratulations on your first Django-powered page'.

Database setup

For most simple and local development it's best to use sqlite. Edit the file '~/Django/mysite/' and make sure to have the following parameters set:

DATABASE_NAME = '/home/your-user-name/Django/mysite/db/mysite.db'

Then, create a folder for your database and sync it:

cd ~/Django/mysite
mkdir db
./ syncdb

You will be asked for an admin username, password and email adress. You will need this information later on.

Create an application

A Django project, such as 'mysite', is a collection of applications. The Django project provides ready made applications that can be used right away to provide special features and components for your project (such as an admin panel). Making a Django project is a combination of ready made generic applications and custom ones that you will write.

Because of this modularity, the application that will write for your project can be used for other projects if needed later on. You can also browse through the many ready to use applications from the Django developers and community.

To create a new application, do the following:

cd ~/Django/mysite
./ startapp myapp

It will create the myapp folder containing basic code to get you started.