Lecture: Blank Slate: Creating an Empty Django Project and App

June 30, 2026, 4 p.m. (America/Los_Angeles)

This lecture covers the steps required to create a Minimum Viable Prototype (MVP) of a Django project and application from a blank folder through a website published locally on your computer.

Lecture Preview

Content

Student Orientation

  • This is not a job. Hopefully you're here because you want to be.
  • I want it to stay that way.
  • If you're getting frustrated, reach out
  • My job: get you through it, via accountability, and solving tech hurdles
  • upcoming: message board

Questions from last time?

Summary of Changes

  • Added app store option for WSL
  • clarified prerequisites
    • removed default-libmysqlclient-dev
  • clarified requirements and cleaned up duplicates
  • fixed git remote add command line bug
  • fixed .gitignore
  • install vscode extensions in window en-masse
  • switched from "codium" to "code"
  • clarification of wsl/vscode install / linking process
    • added ms-vscode-remote.remote-wsl
    • added external links
    • updated virtual environment creation in vscode
  • clarified debug for WSL -- You can!
  • fixed video stream

Github repo access: 2 options

  • ssh
    • can set up to remember forever
    • requires ssh client
  • personal access tokens
    • have to enter every time
    • no other programs required

using SSH

  1. install ssh (if needed)
  2. create a ssh key in your ubuntu environment:

    ssh-keygen -t ed25519 -f <path/to/key>
    
  3. get the public key

    cat </path/to/key>.pub
    

    and copy from the terminal

  4. navigate to https://github.com/settings/keys and add the public key

add to ssh config

cat << EOF | tee ~/.ssh/config
Host github.com
   User git
   IdentityFile /path/to/key
   PreferredAuthentications publickey 
EOF

personal api key

  1. Navigate to https://github.com/settings/tokens and click on the "generate new token (classic)" link
    1. confirm your identity
    2. set name, scope(repos) and expiration
    3. save in your password manager

Git Repository

alt text

https://github.com/danb0b/django_homepage_public

Overview of Django

What is Django?

Django is a Python-based web framework that simplifies the task of creating fully-functional websites. It is over 20 years old, and is one of the most popular web frameworks on the internet.

  • It provides a way of structuring web applications using models (database structures), templates (html plus a schema for blending in data), requests(basic web funtionality that comes from the user), and views (the functionality that blends data, request, and representation together.)
  • It encapsulates the most important functionality into reusable functions and classes, all based on Python. This approach helps keep your project clean and simple even as the complexity grows.
  • It allows you to interact with it at a variety of abstraction levels -- if you are a novice and need only basic functionality, it works easily out of the box. As you learn more and need advanced functionality, it provides access to lower-level functionality that permits you to do what you want

Common built-in features

  • It integrates a templating system so you can merge html with data in a way that is comfortable for Python developers
  • It ships with a user-authentication system that is basic but secure. This system is easily extensible, and can also connect to modern web-based authentication providers. Its documentation is also oriented towards building secure web sites out of the box.
  • It comes with a whole ecosystem of plugins and apps that extend its functionality. These tools are typically open-source and supply what Django doesn't provide out of the box.
  • It can create, manage, and work directly with a wide variety of databases so that you don't have to be an expert in databases and queries.

Creating a New Django Project

let's say you want your project to be your personal website. Let's call it "homepage". Navigate in the terminal to the project directory you created in your last lecture and type the following:

django-admin startproject homepage
cd homepage

You can run the project right away, (though there won't be much to do)

python3 manage.py runserver 0.0.0.0:8000

from the terminal window, type ctrl+c at the same time to kill the server.

Edit settings

open homepage/homepage/settings.py in your favorite text editor. From the command line you can use:

nano homepage/homepage/settings.py

or you can open it in VSCode. Edit the time zone. Comment out:

TIME_ZONE = 'UTC'

And replace it with your local timezone, such as

#TIME_ZONE = 'UTC'
TIME_ZONE = 'America/Los_Angeles'

If you don't know your time zone code, you can find a list of valid time zones by activating your environment and running python in the terminal. From your project folder:

source .venv/bin/activate
python

in the resulting python interpreter type the following lines:

import pytz
pytz.country_timezones('US')

this will return:

['America/New_York', 'America/Detroit', 'America/Kentucky/Louisville', 'America/Kentucky/Monticello', 'America/Indiana/Indianapolis', 'America/Indiana/Vincennes', 'America/Indiana/Winamac', 'America/Indiana/Marengo', 'America/Indiana/Petersburg', 'America/Indiana/Vevay', 'America/Chicago', 'America/Indiana/Tell_City', 'America/Indiana/Knox', 'America/Menominee', 'America/North_Dakota/Center', 'America/North_Dakota/New_Salem', 'America/North_Dakota/Beulah', 'America/Denver', 'America/Boise', 'America/Phoenix', 'America/Los_Angeles', 'America/Anchorage', 'America/Juneau', 'America/Sitka', 'America/Metlakatla', 'America/Yakutat', 'America/Nome', 'America/Adak', 'Pacific/Honolulu']

if you want to find the timezones for a different country, you can replace 'US' with your country code:

pytz.country_names.keys()

Check DB setup

Your settings.py is set already to use a database on the backend, currently sqlite. We will switch to something a bit more scalable later, but this is a really good option for initial internal testing, as it requires less setup and fewer dependencies. Find and confirm that you can find the following lines in settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

Creating an app

Navigate in your terminal to the homepage folder if you are not already there

Create a new blog app:

python3 manage.py startapp blog

You may want to pre-define a custom User model before initializing your database, according to this suggestion: https://docs.djangoproject.com/en/4.0/topics/auth/customizing/#using-a-custom-user-model-when-starting-a-project

Add your new app to the bottom of the list of installed apps.

INSTALLED_APPS = [
    # ...
    'blog.apps.BlogConfig', # Add this line
]

so that it looks like:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog.apps.BlogConfig',
]

We will revisit this later when we want to add plugins, other existing functionality, or another custom app.

Update project-level URL mappings

navigate to homepage/homepage/urls.py Add this code to the bottom (you can clean it up later)

from django.urls import include

urlpatterns += [
    path('', include('blog.urls')),
]

This will map any url to the blog app, but will do so only after checking for urls starting with admin/, which will get routed to the built-in administration app.

Also add a standard way for django to deal with static files. To the same file, add:

# Use static() to add url mapping to serve static files during development (only)
from django.conf import settings
from django.conf.urls.static import static

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Cleaned up, homepage/homepage/urls.py looks like this:

from django.contrib import admin
from django.urls import path
from django.urls import include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('blog.urls')),
]

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Finally, add url mappings to your new app as well. Create a new python file at homepage/blog/urls.py and add the following:

from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='index'),
    ]

Fill in views.py

in homepage/blog/views.py, replace the existing text with the following:

from django.template.response import TemplateResponse

def index(request, *args,**kwargs):
    context = {}
    return TemplateResponse(request, 'index.html', context)

First Templates

We will be adding our first two templates. This will be discussed more in an upcoming chapter, so for now, just follow the directions. First, create the folder homepage/blog/templates as well as the file homepage/blog/templates/base_generic.html within it. Paste in:

<!doctype html>
<html lang="en" data-bs-theme="auto">
  {% load static %}
  <head>

    {% block title %}
    <title>DanAukes.com</title>
    {% endblock %}

    <meta charset="utf-8" />
    <meta name="description" content="" />
    <meta name="author" content="Daniel M. Aukes" />

  </head>
  <body>

    <main class="container">
      {% block content %}
        <p>Default Content</p>
      {% endblock %}
    </main>
  </body>
</html>

In the same folder, create the file homepage/blog/templates/index.html. Paste in:

{% extends "base_generic.html" %}

{% block content %}

<h1>Welcome</h1>

{% endblock %}

Initializing the database

Before running your server, you need to create your database and update its tables to match the classes found in models.py. To do so, enter the next two lines in your terminal, in the homepage/ directory:

python3 manage.py makemigrations
python3 manage.py migrate

You will use the next command to create tables for your app if they do not already exist, or if you have deleted the database and are starting it over from scratch.

python3 manage.py migrate --run-syncdb

This performs a one-time, low-level database creation and is only needed when you changed structure and need to recreate database/tables

and finally you need to create at least one user who can access the admin site with full permissions:

python manage.py createsuperuser

Finally, to run the website for the first time, execute the following in your terminal:

python manage.py runserver

Go to http://localhost:8000. You should see a welcome page looking like this

First welcome page

Finally, type ctrl+c to kill the server

Note: If you want to specify a specific ip address or port, you can expand on the command:

python3 manage.py runserver 0.0.0.0:8000

Update .gitignore

This Content is Locked

The rest of the text is available but you have to be signed in to view it. Please create an account or sign in to continue...