Step 2: Start Project
Okay, ready for the adventure to begin? Unlike PHP or similar things, you can just put your Django project anywhere. If you have no idea, and you are on Ubuntu (which I will assume from now on), create a file called 'project' in your home directory, like this:
In your Terminal, type 'cd' to get get back to your home directory.
vernon@slick:/tmp$ cd
Now, lets make a project
vernon@slick:~$ mkdir projectNow, lets go into that directory:
vernon@slick:~$ cd project
Lets test that Django is on our python path. Type 'python' at the prompt:
vernon@slick:~$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Now type "import django"
>>> import django
>>>
You should see nothing. If you see something like this:
>>> import django
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named django
>>>
then Django isn't on your python path. It probably means that you did something wrong with your installation. Go carefully through the Django documentation and try again.
Okay, if you have Django up and running, the next step is to actually create our project. In your terminal, get out of Python by holding down Control and pressing 'd'. From here on I'll simply say 'press Ctrl-d' and you'll know what I mean.
Okay, now type "django-admin.py startproject zing". I'm calling it zing. You can call it by your name, or your girl/boyfriend or cat's name, or stephanoaetus_coronatus. Anything. I would keep it short, it'll help you when you are repeatedly typing that into your terminal.
vernon@slick:~/project$ django-admin.py startproject zing
That creates a directory called 'zing' (or whatever you named it). If you are not familiar with the Linux file systems, you have a hierarchy of directories, starting from '/' as the base directory, into your '/home/username'. When we created 'project' that would be '/home/username/project' and now with the django project 'zing' that we created inside of it, we get '/home/username/project/zing'. In our terminal we are still in the 'project' directory. Lets go into the 'zing' directory with the 'cd' command again:
vernon@slick:~/project$ cd zing
vernon@slick:~/project/zing$
Now, let's see what we made. To see what is in the directory, we use the command 'ls':
vernon@slick:~/project/zing$ ls
__init__.py manage.py settings.py urls.py
vernon@slick:~/project/zing$
Okay, if you just want to see what is in a file without actually going into it, you can use the command 'cat'. Don't worry if you don't understand anything, or if it looks scarry, just type 'cat' and each of the filenames, '__init__.py' 'manage.py', 'cat settings.py', 'cat urls.py'
vernon@slick:~/project/zing$ cat __init__.py
vernon@slick:~/project/zing$ cat manage.py
#!/usr/bin/env python
from django.core.management import execute_manager
try:
import settings # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've c
.................and so on.....
Mmmm, strange thing that __init__.py file didn't seem to have anything in it. That is a Python thing. Each directory has to have one of those empty files to make Python treat it as a python package.
As for the rest, we'll get there soon
Pat yourself on the back, you've created a Django project. It doesn't do anything, but there it is, all shiny…