ContentsClose contents
Pre-release
Chapter 6 · Creating the project and understanding its filesCHAPTER 06

Six-part pre-release for review, with seven figures and seven tables. Uses uv 0.13.5, Python 3.14.9, and Django 6.1.2. No Otahque app or applied migrations.

Milestone reached in this chapter: First Django page. Your own Django project runs on your computer and shows Django’s welcome page. All milestones

CHAPTER SIX

Creating the project and understanding its files

Stage 1: Requirements and first project (Chapters 1 to 8)

Prerequisites: Chapters 1 to 5, with Chapter 4’s uv and Python checks working

What you’ll build: an isolated Django 6.1.2 environment, a generated Otahque project you can explain file by file, and Django’s development page answering your browser.

Why This Matters

Sam’s proposed design now needs a place to run. In Chapter 5, we followed an event request on paper, through URLs, views, models, and templates. None of that exists on your computer yet, and the first real request is the moment many beginners lose an afternoon: a package installed into one Python and run with another, a project generated into the wrong folder, or a server that seems to answer but is really an old one on the same port.

So this chapter is deliberately careful. We prepare a separate working folder, install Django into an environment we can name, generate the project, and read every file it creates before we change anything. Then we start Django’s development server and open its welcome page. That first page proves that the local project can answer a browser; our own Otahque page begins in Chapter 9.

By the end of the chapter, you will be able to:

  • prepare an isolated environment with the book’s exact Python and Django versions;
  • generate a Django project and distinguish it from a Django app;
  • explain the job of each generated project file;
  • start and stop the local development server and recognize its success page;
  • diagnose common setup problems without overwriting your work.

This is local development: there are no event records or member accounts yet. Django apps follow in Chapter 7; dependency locking and Git follow in Chapter 8.

PAGE 001

What You Need to Know

Three versions, three jobs

We carry uv 0.13.5 and CPython 3.14.9 forward from Chapter 4 and install Django 6.1.2, checked against Django’s official download page on 26 October 2026. Django’s 6.1 installation FAQ lists Python 3.14 as supported. The planned upgrade to Django 6.2 LTS remains a separate later checkpoint. Django 6.1.3, a security release, followed on 3 November 2026; Chapter 53 moves Otahque to it as a step of its own, so the outputs here and in the chapters before 53 show 6.1.2, as it was installed.

Table 6.1 — The three versions used for this setup
Tool Version Job
uv 0.13.5 Select Python, create an environment, and install packages.
CPython 3.14.9 Run Python code, including Django.
Django 6.1.2 Supply the web framework used by our project.

New Tool: Django

What problem exists? Every web application needs the same machinery: matching addresses, reading requests, building responses, talking to a database, protecting forms, and signing people in. Writing it yourself for each project is slow and easy to get subtly wrong.

What did people do before? Developers assembled separate libraries or wrote the plumbing by hand, as the Custom Way in How We Build It shows in miniature.

What is Django? A Python web framework that supplies that machinery as one tested package, with conventions for where each piece lives.

Why Django? Chapter 5 compared the options: it fits a server-rendered first release, a small volunteer team, and the rules Otahque must enforce. Its documentation and long-term-support releases suit a book that will be read for years.

Now let’s install it into an environment we can name.

The double equals sign in Django==6.1.2 asks the package installer for that exact Django release. It is a package version requirement, not the Python comparison expression from Chapter 4. This pins Django itself. Django also needs supporting packages, called dependencies, and the installer selects compatible versions of those. A complete dependency lock records those choices too, which Chapter 8 will teach.

Installation and execution must select the same environment

Installing Django makes its Python package available to one interpreter. It does not create an Otahque project, start a server, or add a website to a browser. The commonest setup failure is installing into one environment and running with another, so every command in this chapter names the environment explicitly with --python .venv. Figure 6.1 shows the idea.

Inside the otahque work folder, both the uv package installation command and the uv run command point to the same .venv environment. That environment contains Python 3.14.9 and Django 6.1.2. A separate system Python sits outside the folder and is not selected.
Figure 6.1 — Installation and execution select the same environment.

Que. 1 The version command prints 6.1.2. Have we created the Otahque website?

Flip to check your answerFold answer back

Answer. No. We have shown that the selected environment can run Django 6.1.2. We still need project files and a running server before a browser can receive a page.

A project collects configuration; an app supplies a capability

A Django project brings together the configuration and apps for a website. Its configuration says which components to use and how they fit together. A Django app is a Python package that supplies a particular capability, such as working with events. A project can use several apps, and an app can sometimes be reused in another project. Chapter 7 develops that distinction and creates our first app.

The word application in Chapter 5 meant the whole running web application. Django app has this narrower meaning. We will use otahque/ as the outer working folder and config as the inner Python package name. The outer folder also holds the environment and a small helper. The package name appears in Python imports such as config.settings, so keep it exactly as shown, and avoid django or any name that hides another installed module. The folder name is not a public domain name.

Que. 2 Why are the working folder and the configuration package named differently?

Flip to check your answerFold answer back

Answer. They have different jobs. otahque/ holds our work; config/ is the Python package containing the site’s configuration. Using distinct names helps us tell a filesystem location from an import path. It does not create two websites or two independently running services.

Under the Hood: what manage.py does

The manage.py file that startproject generates is a few lines long. Its main() function calls os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings'), which names our settings module unless the environment already names another, and then passes the terminal’s arguments to Django’s execute_from_command_line(). That function sets Django up with those settings and runs the requested management command, such as check or runserver. config/wsgi.py and config/asgi.py set the same default before building the application object a server calls.

A local server, a loopback address, and a port

Django’s development server, started with runserver, listens by default on 127.0.0.1 at port 8000. The address 127.0.0.1 is loopback: it refers to this computer, so nothing else on the network can reach it. A port distinguishes one listening service from another at an address. While the server runs, its terminal stays occupied; it has not frozen merely because the prompt does not return.

The server also reports unapplied migrations. A migration is a recorded database change, such as creating tables for an app. The warning is expected, because the generated project enables apps whose tables have not been created. We leave those migrations unapplied: Otahque’s custom user model must be chosen in Chapter 17 before the first migration is applied, and running the command the warning suggests would jump ahead of that decision. This deferral is specific to the fresh development page, which needs no tables. It is not advice to ignore migration warnings in an application that needs its database.

Prefer activating the environment?

Many guides activate a virtual environment so that plain python finds it. Activation works, but it changes your shell invisibly, and a new terminal or an editor may not inherit it. We name --python .venv in every command instead, so each command shows which environment it uses. Chapter 8 introduces uv’s project workflow, which selects the environment for us.

PAGE 002

How We Build It

Starting point: Chapter 4’s readiness checks and Chapter 5’s proposed design; no Django project exists. Begin in a directory where you keep your own work, outside the Chapter 4 practice folder. You need uv 0.13.5, managed CPython 3.14.9, an editor, a terminal, a browser, and internet access to download packages. These steps create otahque/ with .python-version, .venv/, check_environment.py, manage.py, and config/. The visible results are a passing system check and Django’s welcome page in your browser.

The Custom Way: a web answer by hand

Before Django generates anything, it helps to see the smallest possible Python web application. Read this listing; you do not need to run it, and it must not go into your project. It uses wsgiref, from Python’s standard library, to answer exactly one request:

from wsgiref.simple_server import make_server


def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return [b'Hello from a hand-written WSGI app']


with make_server('127.0.0.1', 8000, application) as server:
    server.handle_request()

Run in a scratch folder, it answers one browser visit to http://127.0.0.1:8000/ with that line of text, prints a request log such as "GET / HTTP/1.1" 200 34, and exits. The function named application follows WSGI, the agreement between Python web applications and servers. Everything a real site needs is missing: matching different addresses, templates, a database, forms, security protections, and an error page. That is the work Django’s project files and development server do for us, which is why we generate them rather than write them.

The Django Way: generate and run the project

Step 1: Create a fresh work folder and environment

Open the terminal in your chosen work directory. On Windows, use PowerShell. On macOS, use your usual terminal shell; on Linux or WSL, use Bash. WSL is a separate Linux environment: follow the Linux commands there, with uv and Python installed inside WSL. These commands belong at a shell prompt, not at Python’s >>> prompt.

Check that no folder named otahque already exists here. If it does, inspect it before proceeding. Keep existing work and choose a fresh sibling folder such as otahque-learning instead; use that name in the next command. Do not nest this work inside an old project or reuse the Chapter 4 environment. In PowerShell, a macOS shell, or Linux/WSL Bash:

mkdir otahque
cd otahque
uv --version
uv python pin 3.14.9
uv venv --python 3.14.9

The current directory is now otahque/. The version check should begin with uv 0.13.5; build details may follow. The pin command writes .python-version with 3.14.9. The venv command creates .venv/ using that Python and should report CPython 3.14.9. It may also suggest an activation command; you can ignore it. If these do not match, return to Chapter 4’s version checks before installing anything. A dot at the start of a name often hides it in a file manager; your editor can still open it.

Step 2: Install Django into the environment you name

In the same otahque/ directory, in PowerShell, a macOS shell, or Linux/WSL Bash:

uv pip install --python .venv "Django==6.1.2"
uv run --no-project --python .venv python -m django --version

uv pip is uv’s package-installation interface; it does not require a pip program inside the environment. --python .venv selects the environment for installation and execution. uv run launches the command, and --no-project keeps uv from looking for a uv project’s dependency metadata. The installer reports Django and its supporting packages; download messages, timings, and dependency versions may differ, but the final version command must print 6.1.2. A warning that --no-project found no project is harmless here. python -m django asks the selected Python to run the django module, rather than trusting a standalone django-admin command found elsewhere on your computer.

Step 3: Check the interpreter as well as the package

Create check_environment.py beside .venv/, not inside it. This is a small verification helper, not a Django project file. Do not name it django.py, which would hide the package we want to import. It extends Chapter 4’s environment check with a Django import:

"""Show which Python, environment, and Django run here."""
import sys

import django

print(sys.version.split()[0])
print(sys.executable)
print(sys.prefix != sys.base_prefix)
print(django.get_version())

The first line, in triple quotes, is a docstring: a short description that Python keeps with the module, and that editors and help() show. Every module in Otahque starts with one, following PEP 257, Python’s convention for docstrings. sys.version gives Python’s version text, and split()[0] selects its first part. sys.executable identifies the running interpreter. Different prefix and base_prefix values indicate a virtual environment. The import and get_version() then check the framework available to that same interpreter. Still in otahque/, in PowerShell, a macOS shell, or Linux/WSL Bash:

uv run --no-project --python .venv check_environment.py
uv pip check --python .venv

The helper should print four items. The path line is a placeholder, because your absolute path will differ:

3.14.9
[your otahque/.venv interpreter path]
True
6.1.2

On Windows, the path ends in .venv\Scripts\python.exe; on macOS and Linux it normally ends in .venv/bin/python. Check that it belongs to this otahque folder. uv pip check should report that installed packages are compatible. That check detects dependency problems; it does not verify Otahque’s product rules or security.

Que. 3 An editor runs the helper with a different Python. What should you do?

Flip to check your answerFold answer back

Answer. Compare the executable path with the one printed by the explicit uv command. Select this work folder’s .venv interpreter in the editor, as in Chapter 4, and rerun. Installing Django into whichever other Python the editor happened to choose would leave the mismatch unexplained.

Step 4: Generate the project

Django’s startproject command writes the initial project files. config is the package name. The final dot means the current directory: put manage.py here and config/ inside this folder. Without an explicit destination, Django creates another outer directory named after the project, which would give us a different layout.

Check the folder first. If it already contains manage.py or config/, stop and inspect it rather than running the command again. Existing .venv/, .python-version, and the helper should remain in place.

PowerShell, in otahque/. The backtick continues the command onto the next line; put no spaces after it:

uv run --no-project --python .venv python -m django `
  startproject config .

macOS shell or Linux/WSL Bash, in otahque/. The backslash continues the command; put no spaces after it:

uv run --no-project --python .venv python -m django \
  startproject config .

Choose the block for your shell and run it once. Successful generation normally returns to the prompt without a message. Inspect the files in your editor. This is the expected layout; the contents of .venv/ are omitted:

otahque/
    .python-version
    .venv/
    check_environment.py
    manage.py
    config/
        __init__.py
        settings.py
        urls.py
        asgi.py
        wsgi.py

The new files are manage.py and the five Python files inside config/. Opening or running Python can also produce __pycache__/ folders containing cached bytecode. Those are generated working files, not another Django app and not files to edit.

Common Error: forgetting the final dot

Without the final dot, Django creates an outer config/ folder containing manage.py and another config/ package. The otahque/ folder then has no manage.py, so the next command fails with “can’t open file”. If that happened, inspect the nested layout and compare it with the listing above; do not delete or move files blindly, and do not run startproject again over it.

Step 5: Check the generated configuration

manage.py is the new project’s command-line helper; as the Under the Hood box explained, it selects config.settings for us. In PowerShell, a macOS shell, or Linux/WSL Bash, still beside manage.py:

uv run --no-project --python .venv python manage.py check

Expected result:

System check identified no issues (0 silenced).

This check looks for common configuration problems. It does not open a browser, create account tables, or prove that future registration rules work. If Python cannot open manage.py, check the current directory. If Django cannot be imported, repeat Step 3.

In practice: making a repeatable starting structure

Situation. A second contributor wants the same project layout as Sam.

Application. Record the package name and destination as well as the framework version. The final dot explains why manage.py sits beside .venv/.

Consideration. Generation is a starting action, not a repair command. Repeating it over existing work can encounter conflicts; compare with a freshly generated copy instead, as shown in “When something goes wrong”.

Step 6: Read the generated files

Soni asks which file will eventually connect an event address to Python code. The generated project is small enough to answer by reading it. Open manage.py and the config/ files in your editor; change nothing in this step. Figure 6.2 maps them.

A branch from the otahque work folder separates the environment and helper, manage.py, and the config Python package. Within config, branches identify settings.py as configuration, urls.py as routing, and wsgi.py and asgi.py as server interfaces. __init__.py marks the package.
Figure 6.2 — The outer folder holds the work; the inner package supplies configuration.

The empty config/__init__.py marks config as a regular Python package. The dot in config.settings means the settings module inside that package; it is not a file extension and is different from the destination dot in startproject.

config/settings.py is a Python module of configuration values. Some are strings or Booleans; others are lists and dictionaries, which you practised in Chapter 4. Table 6.2 shows what to notice now.

Table 6.2 — Recognize the generated settings without configuring a release
Setting What to notice now
BASE_DIR The outer project directory, used to build filesystem paths.
INSTALLED_APPS The Django apps enabled for this project; the generated list already includes Django’s own tools.
MIDDLEWARE The configured shared request/response steps introduced in Chapter 5.
ROOT_URLCONF config.urls: the module where root address matching begins.
DATABASES The default SQLite configuration points to db.sqlite3 beside manage.py; configuration does not mean tables exist.
TEMPLATES How Django finds and processes templates; our first template follows in Chapter 11.
DEBUG True for this local exercise; detailed error pages must not be exposed in production.
SECRET_KEY A generated signing secret. Keep it private; each generated project receives a different value.

The generated settings enable Django’s admin, account, session, and other supporting apps. That does not mean Otahque’s event behaviour or account pages exist. Do not paste your SECRET_KEY into a public question or screenshot. The generated value begins with django-insecure- as a reminder that it suits local development only; a deployed system needs a different secret, kept out of shared code.

config/urls.py holds the root URL configuration from Chapter 5. Its urlpatterns list currently contains a route for Django’s built-in admin site, but no event route or Otahque home page yet; Chapter 9 adds our own routing. Do not try to create a superuser or visit the admin as this chapter’s check: it needs database tables we have deliberately not created.

config/wsgi.py and config/asgi.py each expose an object named application that a compatible server can call, the same shape as the Custom Way’s function. WSGI means Web Server Gateway Interface; ASGI means Asynchronous Server Gateway Interface, which also supports asynchronous interactions. They are alternative entry points, not two applications to start together. Django’s runserver uses the WSGI application. Leave both files unchanged; deployment comes much later.

Que. 4 Does the presence of django.contrib.auth in INSTALLED_APPS mean member signup works?

Flip to check your answerFold answer back

Answer. No. It enables Django’s account support as one project component. We still need a chosen user model, database tables, the relevant pages, and application rules. Those arrive in their planned chapters. A setting is not evidence of a complete user journey.

Try it yourself

Write the filename you would inspect for each question: which apps are enabled; where root address matching begins; which command helper selects this project’s settings; and which two files expose the server interfaces. Then rerun the Step 5 system check without editing these files.

Que. 5 What should your file map and check show?

Flip to check your answerFold answer back

Answer. Enabled apps: config/settings.py, in INSTALLED_APPS. Root matching: config/urls.py, selected by ROOT_URLCONF. Command helper: manage.py. Server interfaces: config/wsgi.py and config/asgi.py. The unchanged project should still report System check identified no issues (0 silenced).

Step 7: Run the development server and visit the page

In PowerShell, a macOS shell, or Linux/WSL Bash, in otahque/:

uv run --no-project --python .venv python manage.py runserver

The console includes a system check, the migration warning, the framework version, and the listening address. The following is an excerpt with variable and lengthy output omitted, not a complete transcript:

System check identified no issues (0 silenced).
[Migration warning and timestamp omitted]
Django version 6.1.2, using settings 'config.settings'
Starting WSGI development server at http://127.0.0.1:8000/
[Stop instruction and production-server warning omitted]

With the server still running, enter http://127.0.0.1:8000/ in the browser’s address bar. Use http, not https, for this local exercise; the default local server has no TLS certificate. You should see Django’s successful-installation page with a rocket illustration. The page appears because this is an unmodified development URL configuration with DEBUG enabled. It is Django’s fallback welcome page, not an event template that we wrote, and it will change when we add our own routes. Django may create an empty db.sqlite3 while checking migration status; that does not mean any tables exist.

Inside one computer, the browser sends HTTP GET to 127.0.0.1 port 8000, where the terminal-started Django runserver process loads config.settings and config.urls. A return arrow carries the development welcome page. A note distinguishes this local page from future Otahque pages.
Figure 6.3 — A browser request reaches the local development server.

Look back at the terminal. A line for GET / with status 200 records the successful page request. Refreshing the browser makes another request. The browser may request other resources as well, so count the root-page entries rather than assuming one console line means one entire visit.

Que. 6 Does the welcome page prove that Sai can register for an event?

Flip to check your answerFold answer back

Answer. No. It verifies this local startup and request path. There are no Otahque event routes, templates, models, or registration rules yet. Our first Otahque page starts in Chapter 9, and registration arrives after the database and account work.

Step 8: Stop, observe, and restart

Return to the terminal running the server and press Ctrl+C. On Windows, Django’s startup message says CTRL-BREAK instead; Ctrl+C also stops the server in PowerShell. Wait for the shell prompt to return. Refresh the same browser address: a new request should now fail to connect. An already displayed page can remain on screen, so its presence alone does not prove that the server is running.

Run the same runserver command again, wait for the startup address, and refresh the browser. The welcome page should return. Stop the server again when you finish. Stopping the process does not remove the project or its environment. Django’s development server normally reloads when existing Python code changes; adding some new files may need a manual restart.

Common Error: exposing the development server

If a browser cannot connect, do not open firewall access or bind runserver to all network interfaces to make it work. It is a development convenience, not a production server. Keep its default loopback address, and check the address, the port, and that the server is still running.

Try it yourself

Complete one start, visit, stop, refresh, and restart cycle. Write down the address, the root request’s status while running, and what changes after stopping. Keep the migration warning unresolved, and explain why that is intentional here.

Que. 7 What evidence should the cycle produce?

Flip to check your answerFold answer back

Answer. While the process runs, http://127.0.0.1:8000/ shows Django’s welcome page and the terminal records GET / with 200. After Ctrl+C returns the prompt, a fresh request cannot connect to that stopped server. Restarting restores the page. Unapplied migrations remain expected because we have not configured the custom user or created tables.

When something goes wrong

Raj follows the startup instructions but his browser cannot connect. Reinstalling everything would discard useful clues. Ask instead which step last worked: finding the files, importing Django, loading the configuration, listening on a port, or making the browser request. Table 6.3 covers setup, and Table 6.4 covers startup.

Table 6.3 — Diagnose setup failures while preserving your work
Symptom Check and recovery
uv is not recognized Reopen the shell after Chapter 4’s installation and rerun uv --version. Do not switch to a different installer silently.
The folder or .venv already exists Stop and inspect it. Use a fresh sibling work folder for this setup; keep the original.
Python 3.14.9 cannot be found Return to Chapter 4’s uv python install 3.14.9 step. Check the network if the managed runtime needs downloading.
Package download or certificate error Check your connection and the actual error. On managed networks, ask for the approved proxy/certificate configuration; do not disable verification. Retry the exact install command once access works.
No module named django, or a wrong version Confirm the current directory and that both commands name .venv. If installation failed, retry it there; preserve another environment for comparison.
The helper fails at get_version() Check for a local django.py file or django/ folder hiding the package. Rename your own conflicting helper and retry; leave installed package files alone.
Table 6.4 — Local startup problems and non-destructive recovery
Observed problem Check and recovery
Python cannot open manage.py Inspect the current directory. Return to the folder containing manage.py and .venv/; do not generate another project to hide the path mistake.
Django cannot be imported Run the Step 3 helper with the explicit .venv selection. Check Python and Django versions before retrying installation into that environment.
A syntax or import error names a project file Read the final error and named file/line. If the cause is unclear, compare it with a freshly generated copy, as shown below; correct an accidental edit without replacing your settings wholesale.
The system check reports a problem Read and resolve the actual check message. A failed check is not the expected unapplied-migration warning. Keep checks enabled.
The port is already in use Check whether your own earlier server still runs in another terminal. Stop it there with Ctrl+C, or deliberately choose another free port and change the browser address too.
The browser cannot connect Keep the server terminal open; check startup errors, http, loopback address, and port. A stopped process or HTTPS mismatch is not fixed by changing event code.
A different page appears Confirm the address and the server’s working folder. An older server may answer on the port you visited; the current terminal should record your new request.

These commands were tested on Windows with PowerShell. The macOS, Linux, and WSL forms follow official documentation but have not yet been tested on those systems. If a step fails, keep your folder as it is and work through the tables; never reset your own folder to recover from an error.

Use another port without disturbing a listener

If you cannot identify an existing listener, leave it alone. Do not end an unknown process or relax security settings to clear the error. For a controlled alternative, start our project on port 8001 after ensuring your own earlier server is stopped. PowerShell:

uv run --no-project --python .venv python manage.py `
  runserver 8001

macOS shell or Linux/WSL Bash:

uv run --no-project --python .venv python manage.py \
  runserver 8001

Visit http://127.0.0.1:8001/ and expect the same Django welcome page. If 8001 is also occupied, inspect your open terminals and choose a known free port. Stop the server you started when the check is complete. The port argument does not change project files or apply migrations.

Que. 8 You start on 8001 but refresh the page on 8000. What have you tested?

Flip to check your answerFold answer back

Answer. You have not tested the new listener. The request goes to port 8000, which might have no server or a different one. Change the browser address to the exact URL in the new startup message and confirm that this terminal records the request.

Compare with a fresh copy when needed

If you think a generated file was changed by accident and the error alone does not show what changed, generate a fresh copy and compare that one file. You need this only when something has gone wrong; from Chapter 8, Git will show such changes directly. The commands run startproject in a new, empty sibling folder, so they do not touch your project. If you named your work folder otahque-learning, use that name in place of otahque. PowerShell, starting in otahque/:

cd ..
mkdir otahque-compare
cd otahque-compare
uv run --no-project --python ../otahque/.venv `
  python -m django startproject config .
cd ../otahque

macOS shell or Linux/WSL Bash, starting in otahque/:

cd ..
mkdir otahque-compare
cd otahque-compare
uv run --no-project --python ../otahque/.venv \
  python -m django startproject config .
cd ../otahque

The last command returns you to otahque/. The fresh copy has the same manage.py and five config/ files for this Django version, but no .venv/ of its own. Its SECRET_KEY differs from yours; every other generated line should match. Open the file named in the error in both folders, correct only the unintended change in your own file, and keep your own key. Do not edit the copy, run its server, or copy it over your project. Delete otahque-compare/ when you have finished.

In practice: asking for help with evidence

Situation. Raj reports that the project works in one terminal but not another.

Application. Compare a startup record from both: working directory, interpreter, Django version, check result, and listening URL. The earliest difference is a concrete lead.

Consideration. Exclude your secret key and unrelated private paths when sharing the record. A successful system check does not prove future features; from Chapter 9, each new page behaviour also gains an automated test.

Try it yourself

On paper, diagnose this report: “The helper prints Python 3.14.9, an interpreter in this project’s .venv, True, and Django 6.1.2. The system check passes. runserver says the port is already in use.” Name what already works, what failed, and a recovery that preserves another process.

Que. 9 What should the diagnosis say?

Flip to check your answerFold answer back

Answer. The selected Python and Django import work, and the configuration check passes. Binding the server to its port failed. Leave an unidentified listener alone; stop your own known earlier server or choose a known free port such as 8001, then visit the matching address. No migration or reinstall is needed for a port conflict.

PAGE 003

Verify Your Work

Automated tests begin in Chapter 9. For now, run the checks in Table 6.5 from otahque/, with the server stopped except where a check starts it. All of them must pass before Chapter 7.

Table 6.5 — Verification checklist for Chapter 6
Check Command or action Expected result
Environment uv run --no-project --python .venv check_environment.py 3.14.9, a path inside this folder’s .venv, True, 6.1.2
Dependencies uv pip check --python .venv Installed packages are compatible
Project files Look beside manage.py in your editor manage.py and config/ with five Python files
Configuration uv run --no-project --python .venv python manage.py check System check identified no issues (0 silenced).
Browser page runserver, then visit http://127.0.0.1:8000/ Django’s welcome page, and GET / with 200 in the terminal
Server stopped Ctrl+C, then refresh the browser The prompt returns and a new request cannot connect
Database untouched Recall the commands you ran No migrate command has been run

If the environment line shows another interpreter, return to Step 3. If the browser check fails, use Table 6.4.

PAGE 004

Checkpoint: Quiz and Challenge

Quiz

Que. 10 Why does every command in this chapter name --python .venv?

Flip to check your answerFold answer back

Answer. So that installation and execution select the same environment, visibly, without relying on activation or on whichever Python a terminal or editor finds first.

Que. 11 What does the final dot in startproject config . mean?

Flip to check your answerFold answer back

Answer. The destination: generate manage.py in the current folder and the config/ package inside it, instead of creating another outer folder.

Que. 12 Which generated file says where root address matching begins, and which setting points to it?

Flip to check your answerFold answer back

Answer. config/urls.py, named by the ROOT_URLCONF setting in config/settings.py.

Que. 13 What does 127.0.0.1:8000 identify?

Flip to check your answerFold answer back

Answer. The loopback address, meaning this computer, and port 8000, the port on which the development server listens by default.

Que. 14 Why do we leave the migration warning unresolved?

Flip to check your answerFold answer back

Answer. Otahque’s custom user model must be chosen in Chapter 17 before the first migration is applied. The development page needs no tables, so applying migrations now would only jump ahead of that decision.

Mini-Challenge

Write a startup record you could send with a help request: the current directory, the four lines from check_environment.py, the uv pip check result, the system-check result, and the exact listening address from runserver. Then remove anything private from it. Do not change any project file.

Que. 15 What should a good record contain, and what should it leave out?

Flip to check your answerFold answer back

Answer. It names the working folder, Python 3.14.9, an interpreter inside this folder’s .venv, True for isolation, Django 6.1.2, a compatible-packages result, a passing check, and http://127.0.0.1:8000/. It leaves out the SECRET_KEY and any personal paths or data that are not needed to diagnose the problem.

What We Learned

  • Installing Django makes a package available to one interpreter; naming --python .venv in every command keeps installation and execution in the same environment.
  • A project collects configuration and apps; otahque/ holds our work, and the config package holds the settings, root URLs, and server interfaces.
  • manage.py selects config.settings and runs Django’s management commands; the system check finds configuration problems but proves no product behaviour.
  • runserver answers on the loopback address for development only; the welcome page is Django’s fallback, not an Otahque page.
  • Migrations stay unapplied until the custom user model is chosen in Chapter 17.
  • Failures are diagnosed by the last step that worked, and recovered without regenerating or deleting work.

Key terms

Use Table 6.6 to explain the setup without relying on memorized command sequences.

Table 6.6 — Key terms from Chapter 6
Term Meaning in this chapter
Dependency A supporting package another package needs.
Version pin A requirement for an exact version; pinning Django alone is not a complete dependency lock.
Django project The configuration and apps brought together for a website.
Django app A Python package supplying a capability used by a project.
Python package A group of importable modules; config is a regular package marked by __init__.py.
startproject The management command that generates the initial project structure.
manage.py A project-aware helper for Django management commands.
Settings module The Python module containing project configuration values.
System check A check for common configuration problems, not proof of complete product behaviour.
WSGI / ASGI Interfaces between a compatible server and a Python web application.
Loopback An address, such as 127.0.0.1, referring to the local computer.
Port A number distinguishing a listening service at an address.
runserver Django’s local development server command.
Migration A recorded database change, left unapplied in this chapter.

Readiness checkpoint: identify the work folder and config package; explain each generated file; show Python 3.14.9 and Django 6.1.2 in the intended .venv; run the system check; open the development page at the exact listening address; stop and restart it; and explain why migrations remain unapplied. Return to the relevant step if any result is missing. This is the first local browser result, not a working registration system.

Git Commit

There is nothing to commit yet. Git is set up for the project in Chapter 8, together with .gitignore, so that .venv/ and the secret key are handled correctly from the first commit. From Chapter 8 onward, every chapter ends with a commit.

PAGE 005

Test Your Knowledge: Interview Questions

These five questions rehearse the chapter at interview level, one at each of five levels from junior to lead. L1 and L2 check what you have just learned. L3 asks how it works underneath. L4 and L5 ask about the design and leadership decisions that later chapters build on: attempt them now, and return to them when you reach those chapters. Use the readiness checkpoint to decide whether to continue. If an answer is difficult, revisit its worked example and explain the result in your own words. L4 and L5 are extension questions, not a gate to the next chapter.

L1 (Junior): What is the difference between a Django project and a Django app?

What the interviewer is testing: Do you know which part configures the website and which parts supply its features?

Flip to check your answerFold answer back

Perfect answer: A project is the configuration and the apps brought together for one website: its settings, its root URL configuration, and the WSGI and ASGI entry points that servers use. startproject config . created the config package and manage.py. An app is a Python package that supplies one capability, such as the events app in Chapter 7. A project uses many apps, and an app can be reused across projects, as django.contrib.auth is.

Table 6.7 — A Django project compared with a Django app
Question Project App
What it is Configuration that assembles a website A package that supplies one capability
How many One per website Many per project
Created with startproject startapp
Holds settings, root URLs, WSGI and ASGI entry points models, views, templates, and tests for its capability
Reusable elsewhere? Usually tailored to this website; configuration can be adapted Often, like django.contrib.auth
In our folder config/ events/, from Chapter 7

Behind the scenes:

# manage.py          -> selects config.settings, runs commands
# config/settings.py -> INSTALLED_APPS, MIDDLEWARE, ROOT_URLCONF
# config/urls.py     -> urlpatterns: the root URL configuration
# config/wsgi.py     -> application object for WSGI servers
# config/asgi.py     -> application object for ASGI servers

Code proof: in PowerShell, a macOS shell, or Linux/WSL Bash, beside manage.py:

uv run --no-project --python .venv python manage.py shell -c "
from django.conf import settings
print(settings.ROOT_URLCONF, settings.WSGI_APPLICATION)"
12 objects imported automatically (use -v 2 for details).

config.urls config.wsgi.application

Common mistakes:

  • Creating a new project for each feature.
  • Giving the project package the same name as an app.
  • Treating the project folder as just another app.

Follow-up the interviewer might ask:

  • “Which apps does a new project already include?”
  • “Why did we name the project package config?”

L2 (Mid-Level): What does manage.py do, and how does Django know which settings to use?

What the interviewer is testing: Do you understand how a command finds the project’s configuration?

Flip to check your answerFold answer back
Five numbered steps from top to bottom: you run manage.py with a command; it sets DJANGO_SETTINGS_MODULE to config.settings unless already set; Django imports that settings module; execute_from_command_line runs the command; the command runs with this project’s settings.
Figure 6.4 — How a management command finds the project’s settings.

Perfect answer: manage.py is a small script that sets the DJANGO_SETTINGS_MODULE environment variable to config.settings, unless it is already set, and then runs Django’s command-line utility. Commands such as check and runserver therefore run with this project’s settings. The settings are an ordinary Python module, named by that variable; config/wsgi.py and config/asgi.py set the same default for servers. Because the default only applies when the variable is unset, a production server or a test run can select different settings without editing manage.py.

Behind the scenes:

# os.environ.setdefault('DJANGO_SETTINGS_MODULE',
#                       'config.settings')
# from django.core.management import execute_from_command_line
# execute_from_command_line(sys.argv)
#   -> django.setup() with those settings, then the command

Code proof: from the folder that contains manage.py, in PowerShell, a macOS shell, or Linux/WSL Bash. The quoted text spans three lines; type it exactly, including the final double quote:

uv run --no-project --python .venv python manage.py shell -c "
from django.conf import settings
print(settings.SETTINGS_MODULE)"
12 objects imported automatically (use -v 2 for details).

config.settings

Common mistakes:

  • Running manage.py from another folder.
  • Editing manage.py instead of the settings.
  • Expecting settings in a separate configuration-file format.

Follow-up the interviewer might ask:

  • “What happens if you run a command outside the folder with manage.py?”
  • “How would a production server find the settings?”

L3 (Senior): What does manage.py check examine, and what does a pass not prove?

What the interviewer is testing: Do you know what system checks cover, and avoid treating them as tests?

Flip to check your answerFold answer back
Five numbered steps from top to bottom: run the check command; Django runs every registered check; checks inspect settings, URLs, templates, and models; problems are reported with identifiers; a pass is not proof that the product works.
Figure 6.5 — What the system check does, and where it stops.

Perfect answer: check runs Django’s system check framework. Registered checks inspect the configuration for common problems, such as settings, URL configuration, templates, and models, and report errors and warnings with identifiers such as security.W018. check --deploy adds checks for deployment settings. A pass means no known configuration problem was found. It does not prove that pages work, that Otahque’s rules are right, that the database is ready, or that the site is secure.

Behind the scenes:

# Check functions are registered with @register(tags...);
# deployment checks are registered with deploy=True.
# run_checks() calls every registered function and collects
# CheckMessage objects; ERROR and above stop the command.

Code proof: the new project’s development settings fail the deployment checks, as they should, and the command exits with an error status. PowerShell, in otahque/:

uv run --no-project --python .venv python manage.py `
  check --deploy

macOS shell or Linux/WSL Bash, in otahque/:

uv run --no-project --python .venv python manage.py \
  check --deploy
SystemCheckError: System check identified some issues:
[One error, mail.E001, for the development email backend,
and seven warnings, security.W004 to security.W020,
including DEBUG and an empty ALLOWED_HOSTS]
System check identified 8 issues (0 silenced).

Common mistakes:

  • Treating “no issues” as a test suite.
  • Ignoring warnings.
  • Changing settings only to silence a deployment warning without understanding it.

Follow-up the interviewer might ask:

  • “How would you add a check of your own?”
  • “Which deployment issue would you fix first, and why?”

L4 (Staff): runserver works on your computer. Why must it not serve the public site, and what replaces it?

What the interviewer is testing: Do you know the limits of the development server and what a production setup adds?

Flip to check your answerFold answer back
Five numbered steps from top to bottom: keep runserver for local development; a WSGI or ASGI server loads config.wsgi or config.asgi; a web server or proxy handles HTTPS and static files; DEBUG is off and ALLOWED_HOSTS is set; the secret key comes from outside the code.
Figure 6.6 — What replaces the development server in production.

Perfect answer: Django’s documentation says the development server is for development only: it has not been through security audits or performance tests. It reloads code for convenience, and in this chapter it listens on the loopback address, so only your own computer can reach it. In production, a WSGI or ASGI server loads config.wsgi or config.asgi, usually behind a web server or proxy that handles HTTPS and static files, with DEBUG turned off, ALLOWED_HOSTS set, and the secret key kept out of the code. check --deploy lists what is still missing. Later chapters build that setup.

Behind the scenes:

# runserver serves the object named by WSGI_APPLICATION,
# here 'config.wsgi.application', through Python's simple
# wsgiref server: one process, for local development.

Code proof: the setting runserver follows, in PowerShell, a macOS shell, or Linux/WSL Bash:

uv run --no-project --python .venv python manage.py shell -c "
from django.conf import settings
print(settings.WSGI_APPLICATION)"
12 objects imported automatically (use -v 2 for details).

config.wsgi.application

Common mistakes:

  • Exposing runserver on a public address.
  • Running with DEBUG on in production.
  • Thinking that wsgi.py is itself a server.

Follow-up the interviewer might ask:

  • “WSGI or ASGI for Otahque, and why?”
  • “What does ALLOWED_HOSTS protect against?”

L5 (Lead): How would you make every contributor’s Django setup identical, and what is still missing from our Chapter 6 setup?

What the interviewer is testing: Can you tell a reproducible setup from one that only works today?

Flip to check your answerFold answer back
Five numbered steps from top to bottom: pin the Python version; create one environment per project; pin the Django version; run the same readiness commands everywhere; lock every dependency, which Chapter 8 adds.
Figure 6.7 — From a setup that works today to one everyone can rebuild.

Perfect answer: Pin the Python version in .python-version, create a separate .venv for the project with uv, install an exact Django version, and give everyone the same readiness commands: check_environment.py, uv pip check, and manage.py check. Still missing: a pin on Django alone is not a complete lock, so its dependencies, such as asgiref and sqlparse, and tzdata on Windows, could differ between machines; Chapter 8 introduces that workflow. The project also needs version control, secrets kept out of the code, and automated checks that run the same commands for every change. A lead makes the verified path the easy one, and checks it: each new contributor’s readiness check passes before their first change.

Behind the scenes:

# .python-version  -> 3.14.9            (pinned)
# Django==6.1.2    -> django            (pinned)
# asgiref, sqlparse, tzdata -> chosen by the installer on
# the day you install: not yet recorded anywhere.

Code proof: list what the environment actually contains:

uv pip list --python .venv
Package  Version
-------- -------
asgiref  3.13.0
django   6.1.2
sqlparse 0.6.0
tzdata   2026.5

This is the list on Windows. On macOS and Linux there is no tzdata row, because Django asks for that package only on Windows.

Common mistakes:

  • Sharing a .venv folder.
  • Assuming that the same Django version means the same environment.
  • Recording versions once by hand and never again.

Follow-up the interviewer might ask:

  • “Which files would you commit, and which never?”
  • “How would you upgrade Django safely across a team?”

Next: Chapter 7 introduces Django apps and their boundaries, using this project as the starting point.

PAGE 006