Skip to the resource

Day 1 of 7 · 60–90 minutes

Start Django and open your first page

Create the project, add a blog app, and connect a URL to a simple Python view.

Today you finish withA Django server running with your own homepage.

Today’s goal

Start a small Django project called My First Blog. By the end of today, visiting http://127.0.0.1:8000/ will show a page you created.

You do not need a database, HTML template, CSS, login, or deployment today. One working page is enough.

Before you start

You need Python installed and a terminal open. Check Python with:

python --version

If that command does not work on macOS or Linux, try python3 --version and use python3 in the commands below.

Step 1 — Create a project folder

mkdir my-first-blog
cd my-first-blog

Open this folder in your code editor.

Step 2 — Create a virtual environment

A virtual environment keeps this project’s Python packages separate from other projects.

python -m venv .venv

Activate it on macOS or Linux:

source .venv/bin/activate

Activate it in Windows PowerShell:

.venv\Scripts\Activate.ps1

Your terminal usually shows (.venv) when it is active.

Step 3 — Install Django

python -m pip install django
python -m django --version

The second command should print a Django version number.

Step 4 — Create the Django project and blog app

django-admin startproject config .
python manage.py startapp blog

The final dot in the first command matters. It tells Django to place the project in the folder you already created.

Your important files now look like this:

my-first-blog/
├── manage.py
├── config/
│   ├── settings.py
│   └── urls.py
└── blog/
    ├── views.py
    └── models.py

config holds settings for the whole website. blog is one feature inside that website.

Step 5 — Tell Django about the blog app

Open config/settings.py. Add "blog" near the bottom of INSTALLED_APPS:

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "blog",
]

Do not remove the apps Django added for you.

Step 6 — Create your first view

Replace blog/views.py with:

from django.http import HttpResponse


def home(request):
    return HttpResponse("<h1>My First Blog</h1><p>Django is working!</p>")

A view is a Python function that receives a request and returns a response.

Step 7 — Give the blog its own URL file

Create blog/urls.py:

from django.urls import path

from . import views


urlpatterns = [
    path("", views.home, name="home"),
]

The empty string means the homepage of the blog app.

Now open config/urls.py and connect the project to the blog:

from django.contrib import admin
from django.urls import include, path


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

The request now travels like this:

Browser / → config/urls.py → blog/urls.py → home() → response

Step 8 — Run the server

python manage.py runserver

Open http://127.0.0.1:8000/. You should see My First Blog and Django is working!

Stop the server with Ctrl+C when you finish.

Checkpoint

  • The terminal shows no red error.
  • / displays your heading.
  • You can point to the project URL file, app URL file, and view.
  • You can explain that a URL chooses a view.

If it does not work

What you seeCheck this
No module named djangoActivate .venv, then install Django again.
No module named blog.urlsConfirm the file is exactly blog/urls.py.
views is not definedAdd from . import views to blog/urls.py.
The old page still appearsSave every file and refresh the browser.

Stop here

Today is complete when one request reaches your home() view. Tomorrow you will move the HTML into a proper template and display three sample posts.