Step Two: Installing and setting up a basic Django project

by Andy Boyle.

In this post I will walk you through how to set up a basic Django project on that AWS instance we’ve already set up.

As you remember, after logging in with your terminal application, you’ll be at a prompt. What follows are some basic commands for setting up and installing various tools.


You may need to type “sudo” in front of most of these commands (without the quotes). That stands for “super user do,” which allows you to execute commands without having to login as the root user. First, let’s update the ubuntu we’ve installed. Enter each command individually:

apt-get update
shutdown -r now

That last part will shut down your server and kick you off, so you’ll need to log back in, like I showed you near the end of step one.

Next we will set up various directories that we will use later on. I prefer putting my django-projects in an /opt/ directory, as Jeremy Bowers always made me do. He is smarter than me and eats fancy pork products, so you should listen to him, too. Also, he explains his reasoning in this blog post (which I’ll be referencing a lot in Step Six of this tutorial).

Again, remember you may need to type “sudo” in front of these commands, except the ones that are cd. Enter each command individually:

cd /opt/
mkdir /opt/run/
mkdir /opt/log/
mkdir /opt/log/nginx/
mkdir /opt/lock/
mkdir /opt/django-projects/
chmod -R 777 /opt/

The mkdir command makes a directory. The chmod -R 777 makes a directory read and writeable by all users, which is what you’ll want when you’re setting up your apps. What we’ve done is make the directory where your Django apps will live.

We’ve also added stuff for nginx, which will be our application server. This is our software server, which lives on a physical server running Ubuntu. Think of nginx as the bartender inside of a bar, using my analogy from Step One.


Now you’ll want to enter this command as one line — yes, one line, so copy, past and hit enter — and it’ll install a ton of stuff you’ll need, and some stuff you may never use. But hey, you’ll have it around and it doesn’t really hurt anything.

apt-get install binutils python-psycopg2 python-setuptools libgeos-3.1.0 libgeos-c1 libgdal1-1.6.0 postgresql-8.4-postgis postgresql-server-dev-8.4 haproxy nginx memcached python2.6 python2.6-dev psmisc subversion git-core mercurial python-imaging locate ntp python-dateutil libxml2-dev libpcre3 libpcre3-dev 

That will take a few minutes, and if it asks you any yes or no questions, always answer yes. Let’s make sure python was installed. At your prompt type:


You should have some text pop up about the python version installed, followed by a >>> prompt. That means python is installed! Huzzah. You are now wonderful and can finally do amazing things with your life. Type this to exit:


You already have PostgreSQL installed from that long thing you copy and pasted up there. That will be your database backend. You could use MySQL, sure, but I don’t. And besides, don’t you want to be cool like me? Next let’s install Django.


Type this, remembering you may need to use sudo before each command:

easy_install django pysolr django-storages django-piston pywapi 

I probably just blew your mind. I apologize. We just installed Django along with some other awesome tools. The easy_install function was installed as part of the python setup tools you did when you copied that previous big long command up there.

Now, to make sure Django is installed, go to the python prompt — we did this earlier, remember? — by typing:


Then type at the >>> prompt each line separately and hit enter:

import django

print django.get_version()

It should spit out 1.2.4 (or whatever the most recent stable version of Django is). If so, awesome. If not, back up a few steps and retry to easy_install Django. Then exit, like I showed you a few graphs up, with exit()

Next, go to the directory we want to install our Django app by typing this this:

cd /opt/django-projects/

We shall now make a basic Django application. I will walk you through coding a simple app in Step Three, but for now we will just set up our project and app.


The project we will make shall keep track of fires in your local community that are reported on, an app that Adrian Holovaty, one of the inventors of Django, mentioned newspapers should be doing more than four years ago.

So first we need to make a project directory. We shall name it firetracker. You create the project this way:

django-admin.py startproject firetracker

Now type:


You should see a new directory called firetracker, and then cd into it (cd firetracker).

Type ls again and you’ll see a bunch of files. I will explain what they are in a later post. But this is the project directory. Now you will make an application used this command:

django-admin.py startapp fires

Type ls again. See the fires directory? cd into it. You should see files like models.py, views.py, __init__.py and maybe tests.py. Congratulations! YOU’VE SET UP THE BASICS OF YOUR FIRST DJANGO APP!

Pat yourself on the back. You’ve just done some commands that might scare a regular mortal. Updating a server, downloading and installing new software, this fancy python command. You are on your way to becoming a regular Django Knight, and I salute you.

I highly suggest you go and drink a beer right now before moving on to Step Three: Connecting to your server with an FTP client.