Web development with Django continued - SimpleBlogger Project part 1

THE PROJECTWith Python and Django installed on your system, open your command prompt (for Windows) or bash console (for Mac), navigate to the directory you want the project to reside using the cd command, then enter the following command.

django-admin.py startproject <project_name>

in our example we use;

django-admin.py startproject simplebloggerproject

Running this command creates a Django project with the name you specified in the directory you specified. Don't worry if you don'tsee any change in your command prompt, it is normal. To see what has changed, go to the directory where you created the project (e.g desktop), you should see a new folder with the name of the project you just created. This folder contains two items - a sub-directory with the same name and a python file with the name 'manage'.The sub-directory contains four files namely; __init__, settings, urls and wsgi - all ending with a .py(python's extension).

THE APPDjango is designed to be as flexible and portable as possible, with the DRY (Don't Repeat Yourself) principleat the core of its development processes.

The project created above is a container for any number of applications you want to create. Each of these applications have an independent existence and are connected with urls. This makes it interestingly easy to create pluggable micro-components for for the entire project.

In our example, we will create our first application and we will simply call it "simple_blogger".

To create the app, open your command prompt and navigate to the simplebloggerproject project directory, then run the command below.

This creates the simple_blogger App inside the simplebloggerproject directory.

The App we just created is a directory with six items - a sub-directory with the name "migrations", __init__.py, admin.py,models.py, tests.py and views.py.Each of these files have their unique functions. We will add more file as we proceed.

WHAT WE HAVE COVERED SO FARIf you followed correctly, you should have a project tree similar to the one below.

That's about all we have to do to get our first Django App up and running.

VIEWING THE APP (WEBSITE) ON THE BROWSERBefore we can view what we have so far, we have to complete a few setup.

Open the simplebloggerproject directory and open the settings.py file in any text editor of your choice.On the settings file, locate the INSTALLED_APP tuple and add the name of the application we just created,

INSTALLED_APPS = ( '', 'simple_blogger', )NOTE: Don't forget to add the trailing comma at the end of the App name as shown.

As we create more Apps, we add them to project in the same way. We will explain the other parts of the settings.py as we add more functionalities to the project.

Next step is to initialize our project by migrating the changes we have made together with the default settings and db models automatically created at the point of creating the project and the App.

Back to the command prompt and in the simplebloggerproject directory run the following command.

After you've started your server, open your browser and on the address bar, enter the following

127.0.0.1:8000

If you followed the steps correctly, you should see a congratulatory message. By default, Django runs on port 8000. However, you can specify a different port at the point of running the server like this;

manage.py runserver 9000

This will run the server on port 9000, and to access the App, enter 127.0.0.1:9000 in the browser's address bar.