Tutorial: Starting a Project
Posted: March 15th, 2010 | Author: Adam | Filed under: Django, programming, Python | No Comments »So now that you’ve completed the first part of the tutorial lets actually get started working with Django.
Let’s create folder called “django-projects” and from the command line in that folder
django-admin.py startproject blog
This command uses the built in django-admin command which creates a basic file structure for our project in a directory called “blog”. Let’s take a quick glance at the files that it made for us
- __init__.py - This file is a “magic” python file that we can ignore
- manage.py - This main file for working with your project from the command line. You won’t need to edit this file ever but, you’ll be using it a bit in a few minutes to run a development server, and sync up your database.
- settings.py - Your basic config file. Contains your DB connection data, directory to your templates, what apps and extra Django modules you want the framework to load
- urls.py - This is where we’ll define the URL’s (URI’s) for our application in a minute
This is the backbone for our project. Django define’s a project as a wrapper around many applications. So a single project can have lots of little applications inside of it. Right now we only have a project. Let’s create out application, again from the command line inside of the “blog” project directory
django-admin.py startapp main
Now let’s take a look at the new files that have been created for us
- models.py - This is heart of your application. This is where you define all the models you’ll use in your program, we’ll be getting here very soon
- views.py - If models.py is the heart than this is the brains of your application.
- tests.py - This is a file for testing our application but, out of scope for a simple tutorial
So, lets run your first Django application
$ python manage.py runserver Validating models... 0 errors found Django version 1.1 alpha 1, using settings 'blog.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
You are now running your very first Django application. Congrats! Goto http://127.0.0.1:8000 and check it out
Now that we have the basic framework of our application setup, lets start setting up our database. This is continued in Step 3 of the tutorial

Leave a Reply