Lesson 15 - Creating Your First Django Site (Part 1)

Objective: To spin up your first version of your Django site and build and experiment with a database model.

Materials: Chromebook, Ethernet Cable, Micro SD card w/ Ubuntu Linux 22.04 LTS Image, OLED Display, Raspberry Pi, USB-C Power Supply


For the next several lessons, we will be following an excellent tutorial by an organization called the Django Girls.  Along the way we will make several modifications to the tutorial.  Two of the larger modifications will be the use of postgreSQL instead of sqlite and the hosting of our site will be on Heroku's Platform as a Service (PaaS) instead of PythonAnywhere.

The following are the set of instructions that will help us set up a database, start a virtual environment, install Django, build a model, and finally test our site.  There are quite a few steps here and a lot to setup.  Don't feel discouraged if you get errors along the way - take your time, try to debug on your own, search the web for answers, or ask questions.  The world is filled with many seasoned Django developers that are willing to help others out.

1. First, follow Lesson 13 of the pi-chrome-project.com to create a database, user and password for our Django Girls Blog site.

2. Under the "Installation" section of the Django Girls Tutorial, follow the instructions for installing and activating a Virtual Environment and installing Django.

3. Skip over the "Installation (chromebook)" section.  It is important to realize here that even though we are using a Chromebook, our computer for this project, and all other projects in this course, is the Raspberry Pi itself.  We are using the Chromebook as a terminal to access our Raspberry Pi.

4. Work through the following next sections, as they will serve as a good review and/or introduction to some fundamentals that will help us out greatly in our journey to creating a web application: "How the Internet works", "Introduction to command line", "Introduction to Python", and "What is Django?".

5. Work through "Your first Django Project".  We will make the following modifcations.  Instead of allowing hosts '.pythonanywhere.com', we are going to allow hosts '.herokuapp.com'.  With our virutal environment activated, we will need to enter the command on the command line "pip install psycopg2".  This is an adapter that will allow Python and Django to work with our postgreSQL database.  As a final modification, we will need to jump back into Lesson 13 from the pi-chrome-project.com and pick-up with Digital Ocean's "Configure the Django Database Settings".

6. Back in the Django Girls tutorial, work through "Django models" and "Django amdin".  By the end of these two sections, if all goes well, we should have should be able to run our site locally and access the admin portal of our site.  Please see the images below to get a sense of what you should be seeing.


Resource Links:

Django Girls: https://djangogirls.org/en/

Django Girls Tutorial: https://tutorial.djangogirls.org/en/

Platform as a Service (PaaS): https://en.wikipedia.org/wiki/Platform_as_a_service

PostgreSQL and Django Setup on Ubuntu: https://www.digitalocean.com/community/tutorials/how-to-use-postgresql-with-your-django-application-on-ubuntu-20-04


Pictures:

Successful Django Installation

Successful Django Installation

Django Admin Portal

Django Admin Portal


Videos: None