Skip to lesson content

PROJECT 1 · LESSON 1 OF 16

Install Django and serve Hello World

Build a local Python environment and trace your first browser request.

  • Python
  • virtual environments
  • project vs app
  • HttpResponse

Your workspace: edushop

Start a new practice folder. The completed checkpoint includes all configuration and source files.

Extract the ZIP and open the folder containing manage.py. Create a Python virtual environment, install requirements.txt and run migrate. Read README.md for checkpoint-specific commands and LESSON.md for offline explanations. Checkpoints contain no database records or private credentials.

1. Understand the problem and the concepts

Why we need this feature

A website begins with a request and a response. Before databases, shopping carts or login screens, prove that your Python program can receive a browser request and return something visible. This small result gives you a reliable starting point for every later project.

Use Python 3.12 or 3.13; these checkpoints were verified with Python 3.13 and Django 5.2.18 LTS. Know Python functions, lists, dictionaries and basic classes before starting. This course uses server-rendered HTML, not a JavaScript frontend.

Keep one practice folder named edushop outside the EduPoly website repository. Each checkpoint is cumulative. You can type the files or extract the completed checkpoint, but do not run startproject over an extracted project.

What Django does for you

Python is the language that runs your application. Django is a Python framework that supplies URL matching, request objects, responses, templates, forms, database access and authentication. The browser does not run your Python. It sends an HTTP request to a server, and receives a response such as HTML. You can therefore build this course without React or a JavaScript build tool.

Know variables, dictionaries, lists, functions, imports, basic classes and indentation before starting. You do not need advanced Python, but you should be able to explain a function receiving an argument and returning a value. In our first view the argument is request and the return value is HttpResponse.

Install once, isolate each application

Install Python 3.12 or 3.13 from python.org and a code editor. On Windows, check Python installation with py --version; on macOS or Linux use python3 --version. If python3 is missing, install it before running the commands below. Do not name your own files django.py or typing.py because they would shadow installed modules.

A virtual environment is a folder containing an isolated Python environment. Create it with python3 -m venv .venv on macOS/Linux or py -m venv .venv on Windows. Activate with source .venv/bin/activate on macOS/Linux, or .venv\Scripts\Activate.ps1 in PowerShell. If activation is restricted, run .venv\Scripts\python.exe directly; no policy change is necessary. Once activated, python -m pip installs into this environment.

Use Django 5.2.18 for the course checkpoints. The 5.2 LTS series gives a consistent learning target; follow security updates before operating a real store. requirements.txt records the version so a second machine installs the same framework. A dependency file describes what to install; it does not contain the installed packages.

Project, app and the two ways to start

The outer edushop directory is your workspace. config is the Django project package: it connects settings and top-level URLs. shop is a Django app: a feature package that will grow into the storefront. One project can contain multiple apps, which is why tasks and orders join later. manage.py runs commands using this project’s settings.

Choose one starting method. To build from scratch, use the terminal scaffold commands and then replace the listed files. To use the completed download, extract it, open the directory containing manage.py, create a virtual environment there and install requirements.txt. Do not run startproject inside a completed checkpoint. After installation run python manage.py migrate, then python manage.py runserver and open http://127.0.0.1:8000/.

runserver is a development server. Keep that terminal open while browsing; Ctrl+C stops it. It reloads Python changes during development. A browser refresh sends a new request. Deployment later uses Gunicorn, a process manager supplied by hosting, PostgreSQL and production settings.

2. Follow the execution flow

Read this sequence before the source. Identify the input, the component or function that handles it, and the result the learner sees.

  1. The browser requests GET / from port 8000.

  2. Django loads config.settings and its root URL configuration.

  3. The empty path matches the home view in shop.

  4. home receives an HttpRequest and returns HttpResponse.

  5. The browser displays the response body; a refresh repeats the sequence.

Read your first request like a developer

  1. Start the server and visit /. Locate the GET / entry and status 200 in the terminal.
  2. Change the greeting in the view, save, and refresh. The response changes because the server executes the edited function.
  3. Stop the server and refresh again. The browser cannot connect: the browser tab is a client, not the application server.

3. Build it, one file at a time

  1. Install Python from python.org and confirm its version. Create edushop and a virtual environment using the platform commands below.
  2. For the from-scratch path, install Django, run python -m django startproject config . and python manage.py startapp shop. Replace the generated files with the complete files below and create missing parent folders. For the download path, the project and app already exist.
  3. From the folder containing manage.py, run python -m pip install -r requirements.txt, python manage.py migrate and python manage.py runserver. Open http://127.0.0.1:8000/.
  4. Change the heading in shop/views.py, save and reload the browser. Unlike Next.js hot UI updates, the browser generally needs a reload to see a Django page response.
Terminal
# macOS / Linux — from a new working folder
python3 --version
mkdir edushop
cd edushop
python3 -m venv .venv
source .venv/bin/activate

# Windows PowerShell — use these instead of the activation commands above
# py -3 --version
# mkdir edushop
# cd edushop
# py -3 -m venv .venv
# .\.venv\Scripts\Activate.ps1
# If activation is blocked, invoke .\.venv\Scripts\python.exe directly.

# From scratch only: skip these three lines when using the ZIP
python -m pip install Django==5.2.18
python -m django startproject config .
python manage.py startapp shop

# After adding the lesson files (or extracting the checkpoint)
python -m pip install -r requirements.txt
python manage.py migrate
python manage.py runserver

The paths below are relative to your practice project. Each block is the complete file at this checkpoint. Read its responsibility first, type or copy the code, then use the walkthrough to explain the important statements.

requirements.txt

Pin the teaching framework so all learners use the same API baseline.

requirements.txt
Django==5.2.18

Read the code

  1. Install through python -m pip inside the virtual environment so the interpreter and packages agree.
  2. Check supported security updates before maintaining a public application; a course pin is not a promise to ignore future fixes.

manage.py

Run Django management commands with this project’s settings.

manage.py
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
    from django.core.management import execute_from_command_line
    execute_from_command_line(sys.argv)

Read the code

  1. DJANGO_SETTINGS_MODULE names a Python module, not a filesystem path.
  2. sys.argv contains the command such as migrate or runserver. You normally use manage.py rather than editing it.

config/__init__.py

Mark config as a Python package.

config/__init__.py

Read the code

  1. This file is intentionally empty. Its presence makes the package structure explicit.

config/settings.py

Configure this Django project and register its applications.

config/settings.py
from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent.parent
# Local learning only. Project 8 replaces this with required production configuration.
SECRET_KEY = "development-only-edupoly-do-not-use-for-a-live-site"
DEBUG = True
ALLOWED_HOSTS = ["localhost", "127.0.0.1", "testserver"]
INSTALLED_APPS = [
    "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes",
    "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles",
    'shop',
]
MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = "config.urls"
TEMPLATES = [{
    "BACKEND": "django.template.backends.django.DjangoTemplates",
    "DIRS": [BASE_DIR / "templates"], "APP_DIRS": True,
    "OPTIONS": {"context_processors": [
        "django.template.context_processors.request",
        "django.contrib.auth.context_processors.auth",
        "django.contrib.messages.context_processors.messages",
    ]},
}]
WSGI_APPLICATION = "config.wsgi.application"
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": BASE_DIR / "db.sqlite3"}}
AUTH_PASSWORD_VALIDATORS = [
    {"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"},
    {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
    {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
    {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
]
LANGUAGE_CODE = "en-us"
TIME_ZONE = "Asia/Kolkata"
USE_I18N = True
USE_TZ = True
STATIC_URL = "/static/"
STATIC_ROOT = BASE_DIR / "staticfiles"
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
LOGIN_URL = "login"
LOGIN_REDIRECT_URL = "tasks:list"
LOGOUT_REDIRECT_URL = "shop:home"

Read the code

  1. INSTALLED_APPS enables model discovery, templates and management features. Adding a directory alone does not register an app.
  2. MIDDLEWARE wraps requests in order: sessions precede authentication, and CSRF protects unsafe form submissions.
  3. DIRS finds the shared templates folder; APP_DIRS also searches installed app templates. SQLite stores local records in db.sqlite3.
  4. This development configuration is intentionally replaced in Project 8. Its fixed local key and DEBUG=True must never be deployed.

config/urls.py

Dispatch incoming paths to the correct application.

config/urls.py
from django.contrib import admin
from django.urls import include, path

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

Read the code

  1. Django tries URL patterns in order. include delegates the remaining path to an app-level URL configuration.
  2. The admin has its own URL configuration. Naming and namespacing application routes avoids embedding path strings throughout templates.

config/wsgi.py

Expose Django to a WSGI-compatible production server later.

config/wsgi.py
import os
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
application = get_wsgi_application()

Read the code

  1. Gunicorn imports application from config.wsgi.
  2. runserver is for development; the final project uses this entry point for deployment.

shop/__init__.py

Mark shop as the application package.

shop/__init__.py

Read the code

  1. Django apps organize related behavior within a project. An app is not a separate server.

shop/urls.py

Map the empty remaining path to the home view.

shop/urls.py
from django.urls import path
from . import views

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

Read the code

  1. views.home is a function reference; do not call it while defining urlpatterns.
  2. app_name creates the shop namespace, allowing shop:home to identify the route.

shop/views.py

Return the first HTTP response.

shop/views.py
from django.http import HttpResponse

def home(request):
    return HttpResponse("<h1>Hello, Django!</h1><p>My first working website.</p>")

Read the code

  1. Django supplies request when it calls home. The function returns HttpResponse, not a Python string by itself.
  2. The response body contains a small HTML document fragment. A later lesson moves markup into templates.

.gitignore

Exclude local environments, databases and generated assets from source control.

.gitignore
.venv/
__pycache__/
*.pyc
db.sqlite3
.env
staticfiles/

Read the code

  1. Commit source and migrations, not the SQLite database or virtual environment.
  2. A .gitignore rule does not remove secrets already committed; never add real deployment credentials to source.

4. Run it and check your result

  • GET / displays Hello, Django! in the browser.
  • python -m django --version prints 5.2.18 and python manage.py check reports no issues.

5. Predict, change and observe

Change only the text returned by home. Predict whether a database migration is required.

Compare your prediction with the expected result

What you should observe

The new text appears after reload and refresh; no migration is needed.

Why it happens

A response string is application behavior. Migrations change database structure, and this view does not query a model.

6. Troubleshoot with evidence

A common mistake

If importing Django fails, check which Python interpreter is active. Do not install globally to mask a virtual-environment mismatch.

No module named django

Likely cause: The selected Python does not have Django installed.

Check and correct: Activate the environment and run python -m pip install -r requirements.txt. Compare python -m pip --version with the environment path.

Cannot open manage.py

Likely cause: The terminal is in the wrong directory.

Check and correct: Open the extracted edushop folder containing manage.py. Do not run project commands from its parent folder.

7. Practice and explain it back

Your independent task

Add a second paragraph describing your future store.

Attempt these questions before opening the explanations. Use the source above to justify your answer.

Why not install every dependency globally?

Separate environments let two projects use different versions without replacing each other’s packages. The virtual environment stays local; requirements.txt travels with the source.

Is shop another server?

No. It is a Python package loaded by the same Django process. The app separates related features; config connects those features into one website.