Create your first Django Project.

Site Admin
Posts: 178
Joined: Tue Sep 29, 2009 6:25 pm
Location: Moss Norway

Create your first Django Project.

Postby KBleivik » Mon Jan 31, 2011 9:28 pm

I use the following book chapter 2 to set up a blog on Windows.

1. Create a project.

In DOS prompt issue:

md py\django
cd py\django startproject mysite
cd mysite

Now you have a Python Django project folder - py\django - with a mysite project folder with the following Python files:

2. Run Django's built-in Webserver.

At the DOS prompt issue: runserver

If everything is OK, you should get a message that the server is running at

Open that address in your browser and you should se a page that start with the message: "It worked".

3. Creating the Blog Application

Quit the Web Searer (CTRL + Break) and at the DOS prompt in the c:\py\django\mysite folder issue: startapp blog


Go to the bottom of the file and in INSTALLED_APPS tuple add the following line


save and close the file.

4. Choose your Python editor and design your model.

Now you have to edit your file that you find in the blog folder you just created. For the purpose of editing Python source code, we use a Python editor like IDLE or SPE that can both be downloaded with Python 2.5.1 from the following ... ml#windows windows installer. We prefer SPE (Stani Michiels Python Editor) that can also be downloaded from the internet (e.g. Load the editor from windows and open the file c:\py\django\mysite\blog\

Delete the comment starting with #, and add the following lines:

Code: Select all

class BlogPost(models.Model):
    title = models.CharField(max_length=150)
    body = models.TextField()
    timestamp = models.DateTimeField()

That is Python's object oriented code and if you master that, you will see that the BlogPost class is a subclass of an existing Django class, django.db.models.Model.

Save the file.

5. Setting up the Database

Since we use Python 5.2.1 and run our project on windows, we use the SQLite database that is distributed with Python 5.2.1. (Browse or search the Python25 library where you installed Python). SQLlite is not a stand alone database server like MySQL, Oracle or PostGreSQL that we would use on a web site. SQLite uses the file system on your disk and a database is simply a file. So in the c:\py\django folder go to the DOS prompt and make a new folder, db by issuing:

md db

We name our database, django.db. So the only thing that remains is to edit the file that we created in the c:\py\django\mysite folder. So in that folder issue:

edit the database settings in to:

Code: Select all

    'default': {
        'ENGINE': 'sqlite3',           
        'NAME': r'c:\py\django\db\django.db',

and save the file.

Now you can make some tables in your database by issuing: syncdb

at the DOS prompt. The screen is filled with what is created. At the bottom you can read:

You just installed Django's auth system, which means you don't have any super users installed. Would you like to create one now? (yes/no): yes

and fill in the requested information like user name etc. When everything is OK, at the DOS prompt issue:


to observe that django.db is created as a file in your file system in the c:\py\django\db directory.

Continue here if you wan't to build a fast blog.

To learn Django, you can start on the official Django site: The
documentation is so good that it can be read as a book.
Here is our recommended path through the

1. Get a Birds eye view of the Framework. Read what is written on the home page.
2. Get an overview of the Django framework.
3. Continue with the 4 tutorials:
4. We also recommend the above mentioned book:
5. Participate in the Django community:
6. Google group:

Here you get a list of web pages developed with the Django framework.

Return to “Django”

Who is online

Users browsing this forum: No registered users and 1 guest