Django Installation and First App Tutorial

Django Installation and First App Tutorial

Python Django Tutorial

Django Installation and First App Tutorial

Django Installation and First App Tutorial: Django is a powerful web framework written in Python used to create pluggable database driven websites that are complex, but simplified by the abstraction of the Django framework. I am using Ubuntu for this install but beyond it will work for most OS’s. I will configure Django to use sqlite as a database. It can easily be swapped to use PostgreSQL, MySql, Sqlite or an Oracle database. The installation is pretty simple, getting to know the configuration files and framework is quite a bit more complicated depending on how much experience with Python and web development you have. For that reason, this is a super simple tutorial to break someone in to how Django operates.

For a quick review of Python a couple of tutorials can be found here. This tutorial has lots of pictures and makes the default polls tutorial a little easier to follow, theoretically :). One other reason to learn the Django framework is OpenStack uses it for Dashboard so it might help for editing templates or custom scripting.

Django Installation Tutorial

We will use Pip for the installation. Pip is a package management system used to install and manage software packages. Pip is platform agnostic just as Python itself. It is a replacement/wrapper for easy_install.

That put files into the /usr/local/lib/python2.7/dist-packages/django/ directory.

First Django Project

We will create out first project with the ‘ startproject’ command. Get to know Django admin with


To: django python
Figure 1. should look like this.
$ cd /home/brent/firstsite
Synchronize the manage.db Sqlite database file. *Note, is in the root of the site directory not in the project directory.
$ python syncdb

django root account password
Figure 2. You will asked some questions to setup an account and password at this point.
Look in the directory now, you should see firstsite.db for the sqlite database

Start the Django Development Server

Let’s start the barebones Django framework.
Run this to start the server on all interfaces on TCP port 8000:

python runserver

Figure 3. Server will look like this on startup on the CLI.
Test the default page in a browser at http://Host IP:8000
Ctrl+C to stop the server

default django website
Figure 4. The default page will look something like this.

Enable the Django Admin Control Panel

The admin site is not active by default. We already edited to enable the admin panel in that file. Now we need to edit in your project folder and uncomment three lines. These are the mappings to project pages. Since these sites are dynamically created there isn’t a htdocs like file.
$ nano cd /home/brent/firstsite/firstsite/
Edit from:
Under installed Apps list:

To the following Uncomment ‘django.contrib.admin’,:

django app
Figure 5. should look like this.

Next we need to enable Django to answer the to answer for the /admin/ directory. uses regular expressions to match URL calls. For a tutorial on regular expressions click here. We will also add a regular expression to match the site of the App we will be creating ‘polls.views.index’ to setup the default index view for the App “polls”.

Edit From:

In the following, uncomment three lines and it to:

Figure 6. will look like this.

Create Your First Django App

Create an App named “polls”. This is part of the modularity of Django since the App is decoupled from the web framework. A more advanced approach would be to create a file in your App directory instead of using the sites For now we will keep it simple.

Change From:


django app
Figure 7. Add your polls App into


$ nano /home/brent/firstproject/polls/
Change /home/brent/firstproject/polls/

To: django
Figures 8. will look like this.

Add the App to the Admin Control Panel in

Create in the polls directory
$ nano /home/brent/firstproject/polls/

Figure 9. The file

The last configuration is to edit That is the view you will see in that directory that is called from
$ nano /home/brent/firstproject/polls/
# Create your views here.

Figure 10. will look like this.

Sync the DB and start the development server.

django admin control panel app

Figure 11. The admin control panel looks like this with your app in there.

Now point your web browser at the polls directory. http://host ip:8000/polls/

Figure 12. You should see your first ub3r l33t App!


This tutorial is barely touching the surface. There are tons of them at the following links.

Installation Guide and the Complete Polls tutorial to actually do something:

Hope this helps a couple folks cause I have spent some frustrating times learning the bits and pieces I know now of the framework here and there 🙂 Happy Hacking!

About the Author

Brent SalisburyI have over 15 years of experience wearing various hats from, network engineer, architect, devops and software engineer. I currently have the pleasure of working at the company that develops my favorite software I have ever used, Docker. My comments here are my personal thoughts and opinions. More at Brent's BioView all posts by Brent Salisbury →

  1. Hey Brent,
    You’ve inspired me to get cracking into Django. Setting up my first app now. Thanks for the post.

    /John H the C

    • Brent SalisburyBrent Salisbury11-04-2012

      Awesome John, Let me know what you get into. I keep meaning to dig into node.js too but havent seemed to nail down the whole freeze time for 2 years to catch up on everything I am meaning to do 🙂 Cheers brother.

  2. Dan DonovanDan Donovan11-04-2012

    Hello there,

    I’ve been at this for the past few hours, I installed django and opened up my python shell and verified the version. When i go back and try to set up a new site I get command not found. Do you know what I am doing wrong?

  3. Brent SalisburyBrent Salisbury11-04-2012

    Hi Dan, I wonder if you are running into the Python $PATH being different from your bash/shell path? Python can be tricky with paths unfortunately. Virtualenv might help too. Take a peek here and the official guide linked in the post.

    See if that helps, if not paste what you are seeing and I can poke around.

  4. Dan DonovanDan Donovan11-04-2012

    I think that is it. I checked my environment variables for both the user and the system and I didn’t see anything in there linking them to python or django.

    Can you walk me through it so I dont mess anything up?


  5. Dan DonovanDan Donovan11-04-2012

    Ok well I just went ahead and set them. From the shell I tested it (by the way I am using the GIT GUI shell on windows).

    First I typed in
    $ python
    from there python booted up and I got the >>>
    so I typed import django and then django.get_version() and everything works.

    Next I exited python and tried to set up the test site from the tutorial.
    $ startproject mysite
    I get the same error.

  6. ChrisChris04-04-2014

    Nice tutorial about Django tutorial application, is possible to upload this to GAE? i tried but i have not fixed it.