Building a To Do Application in Python using Django Framework – Part 01

This is a project that will be part of my portfolio. It is supposed to showcase the usage of forms in Django.

For this project I am going to use Cloud 9, which is an online IDE (www.c9.io). Just create a new blank workspace on cloud 9 for this project and you are good to go.

The to do app has to have the following features:

  • A home page with a short description of the app
  • A to do page where you can add, edit, and delete a to do item

Step 1 – Installing Django

For this particular project I am going to use Django 1.11. To install it you have to run the following command in the terminal:

sudo pip3 install django==1.11

The output should look like shown below:

Downloading/unpacking django==1.11
  Downloading Django-1.11-py2.py3-none-any.whl (6.9MB): 6.9MB downloaded
Downloading/unpacking pytz (from django==1.11)
  Downloading pytz-2018.3-py2.py3-none-any.whl (509kB): 509kB downloaded
Installing collected packages: django, pytz
Successfully installed django pytz
Cleaning up...

Step 2 – Create the project

Once Django is installed, we can start our project. To create a project you need to run the following command in the terminal:

django-admin startproject todoapp

Once you create it you can switch to the newly created folder (I named it todoapp, see the command above) by running the following command in the terminal:

cd todoapp

At this point you should have something like shown in the image below:

To do app with Python and Django

The startproject command creates the project folder named todoapp in our case, which contains another folder with the same name. The second todoapp folder contains a few very useful files which we will need to use and it also gives us a file named manage.py which we will use for creating our apps within the project.

Step 3 – Create the apps

The project is going to contain two apps: a home app and a todo app. Let’s create them!

You can create an app in Django by running the following command in the terminal:

python3 manage.py startapp home

You do the same for the todo app by replacing the home with todo. Your folder structure should look like shown below:

To do app with Python and Django

Now, it is a good time to try to see if everything works. To do that, we need to start the server by running the following command (which will not work and I will explain why):

python3 manage.py runserver

If you develop on your local machine then this command will work just fine. In cloud 9 you have to run the following command:

python3 manage.py runserver 0.0.0.0:8080

You will get in the terminal the link to open the app in the browser. You will get first a screen where you have to click on open app button then you will be taken to this screen:

To do app with Python and Django

It says very clearly what you have to do. You can see my screen below:

To do app with Python and Django

Once you added it to the allowed hosts in the settings file you just need to save it then go and refresh the browser. Now you have a web page that says “It worked”.

This is it for part 1. In part 2 we are going to write URLs and views for our project.

Leave a Reply