ContentsClose contents
Pre-release
Chapter 14 · Tailwind, daisyUI, and Otahque's design systemCHAPTER 14

Complete six-part pre-release for review. Sample events are in memory and are not published records.

Milestone reached in this chapter: Browsable event pages. A styled list of upcoming events, labelled as sample data, with a page for each event and the first automated tests. All milestones

CHAPTER FOURTEEN

Tailwind, daisyUI, and Otahque's design system

Stage 2: Pages and design (Chapters 9 to 14)

Prerequisites: Chapters 4 and 6 to 13, including the Chapter 13 project, its 16 passing tests, its Git repository, and your own .env

What you’ll build: a reproducible Tailwind CSS and daisyUI build that compiles one authored source into the stylesheet Django already serves, giving the sample pages a small Otahque theme with readable cards, underlined links, and visible keyboard focus.

Why This Matters

Soni opens the Chapter 13 pages again. The navy bar, the centred column, and the white event card make them easy to read, and she can tell where the navigation ends. Sam, though, is looking ahead. The next pages need event details with dates and venues, a registration page, and an organizer’s list, and each will want cards, spacing, labels, and the same blue for links. In Chapter 13, every one of those decisions is a value typed into one stylesheet, and every new page would add rules that repeat them, each a little differently.

A design system prevents that drift. It is a small shared vocabulary: named colours, a fixed scale of spacing, and a few agreed components that every page is assembled from. It is not decoration. Its job is to keep pages consistent, and to keep the readable, keyboard-friendly choices from Chapter 13 in place as the pages multiply.

This chapter adds two tools that Otahque’s interface plans already chose. Tailwind CSS is a compiler that turns class names written in templates into CSS. daisyUI is a Tailwind plugin that adds named components and a theme. Together they produce the same static/otahque/site.css that Django already serves, so the routes, words, escaping, and tests stay as they are. It is also the last piece the first milestone needs: a styled list of sample events that Soni can browse, with every claim about it checked.

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

  • explain what a CSS build step does, and where Node.js and npm fit beside uv;
  • install exact versions of Tailwind and daisyUI and reproduce them from a lockfile;
  • compile an authored source into the file the layout already links, and test that the output holds what the templates use;
  • choose between utility classes, component classes, and your own rules, and keep class names literal;
  • define a small Otahque theme with named colour roles, and measure its contrast and focus;
  • check a design change with tests, the build, and the browser, each for what it can prove.

The theme is one light theme for fictional sample data on server-rendered pages. There is no dark-theme switch, no JavaScript component, no custom font or image, and no custom 404 page. Collecting, compressing, and caching static files for a real server is part of deployment in Chapter 63. We add a frontend build tool, but no Python dependency, model, or migration.

PAGE 001

What You Need to Know

From hand-written CSS to a design system

Chapter 13’s stylesheet is about sixty lines, and every colour in it is typed as a value. That is fine for three pages. As pages grow, teams usually combine four kinds of styling, and Table 14.1 compares them.

Table 14.1 — Four ways to style a page compared
Approach What you write Where the CSS comes from Good for
Hand-written CSS Rules with selectors and values, as in Chapter 13 You write every rule Otahque-specific details
Utility classes Small one-job classes in the HTML, such as p-4 A compiler writes a rule for each class it finds Spacing, layout, and colour on one element
Component classes One class for a familiar piece, such as card A library supplies the rules Pieces that repeat with the same structure
Theme tokens Named values, such as --color-primary You define them once Values that many rules share

A token is a named design decision, such as “the primary colour is #0759ce”. Rules refer to the name, so changing the value in one place changes every use. The best names describe a role, what the value is for, rather than what it looks like: primary for links and main actions, neutral for the navigation, base-200 for the page behind the cards. Chapter 13 gave the same advice for class names: event-row stays true when the colours change, and blue-box does not.

New Tool: Node.js and npm

What problem exists? The Tailwind compiler and the daisyUI plugin are written in JavaScript. Something has to run them, and something has to install exact versions of both and record them.

What did people do before? They linked a framework’s stylesheet from a content delivery network (CDN) at an address whose contents could change, or downloaded files by hand and lost track of which version they had.

What are Node.js and npm? Node.js runs JavaScript outside a browser. npm, which comes with it, installs the packages that a project’s package.json lists into a node_modules folder, and records the exact versions it installed in package-lock.json.

Why use them? It is the arrangement uv gave us in Chapter 8: a project file says what we need, a lockfile pins what was installed, and a clean install reproduces it on any computer. Django never runs Node. It only serves the file that Node’s tools produce.

Now let’s use it.

Table 14.2 sets the two side by side. They stay separate: uv manages Python and Django, npm manages only the CSS build tools, and neither file mentions the other’s packages.

Table 14.2 — uv and npm side by side
Job uv (Chapter 8) npm (this chapter)
Project file pyproject.toml package.json
Exact record of what was installed uv.lock package-lock.json
Installed packages .venv/ node_modules/
Reproduce exactly from the lockfile uv sync --locked npm ci
Run a tool from the project uv run python manage.py ... npm run build
Kept out of Git .venv/ node_modules/

New Tool: Tailwind CSS

What problem exists? Writing a rule for every combination of spacing and colour makes a stylesheet grow and drift. Loading a whole prebuilt framework stylesheet sends thousands of rules that no page uses.

What did people do before? They grew hand-written sheets, as in Chapter 13, or linked a complete framework stylesheet such as Bootstrap and overrode the parts they did not want.

What is Tailwind CSS? A CSS compiler, version 4.3.4 in this book. It reads one input stylesheet and the files that input names as sources, finds the class names written in them, and writes one output stylesheet. The output has a rule for each Tailwind class it found, a reset that comes first, and anything else written in the input.

Why Tailwind? The output holds only what the pages use, and the class names follow a fixed scale: p-4 is always 1rem of padding and p-6 is always 1.5rem, so spacing stays consistent without anyone remembering numbers.

Now let’s use it.

Here is the class list the layout’s main element will carry at the end of this chapter. Read it as five small instructions:

<main class="mx-auto max-w-2xl space-y-4 px-4 pt-6 pb-12">

mx-auto centres the element with automatic side margins. max-w-2xl limits its width to 42rem. space-y-4 puts 1rem of space between each pair of children. px-4 adds 1rem of padding at the left and right, and pt-6 and pb-12 add 1.5rem above and 3rem below. Each class is one declaration you already know from Chapter 13, given a short name. The browser never sees the name mx-auto as anything special: it is an ordinary class selector in the compiled file.

Tailwind 4 writes CSS for current browsers: Chrome 111, Safari 16.4, and Firefox 128, or later. Older browsers may ignore some rules. That boundary comes with the tool, so we state it rather than promise more.

New Concept: utility, component, and semantic classes

What problem exists? Each style decision has to live somewhere: in the stylesheet under a name, or in the template beside the element it affects.

What did people do before? Chapter 13 put every decision in the stylesheet under an invented name, such as event-row. Each new variation needed another name and another rule.

What are the three kinds? A utility class does one job, such as p-4. A component class names a familiar piece with several declarations behind it, such as navbar or card. A semantic class is our own name for an Otahque idea, such as sample-label, with its rule in our source.

Why mix them? Utilities suit layout and spacing on one element. Components suit pieces that repeat with the same structure. Semantic classes suit Otahque’s own meanings, and elements we cannot or should not put utilities on.

Now let’s use it.

A row in the event list will combine all three: event-row names what the element is, card is the component, and border border-base-300 bg-base-100 p-4 adjust it. Keeping the semantic name costs nothing and tells the next reader, and the tests, what the element is for.

Preflight: the reset that comes first

Browsers start every page with their own default styles, and they do not all agree. Tailwind’s output therefore begins with Preflight, a reset that removes those defaults so that every browser starts the same. It removes margins, makes headings the same size and weight as body text, removes list bullets, and makes links take their colour from the surrounding text, with no underline.

That last change matters. Chapter 13’s links were blue and underlined because the browser’s defaults made them so, and our stylesheet only changed the blue. After the first build, links would look exactly like the text around them. We restore what we need on purpose: headings get a size again, and links get the primary colour and an underline.

The underline is not decoration. Our link blue against the dark body text measures 2.40:1, below the 3:1 that WCAG 2.2 expects when colour alone tells a link apart from the words around it (Success Criterion 1.4.1, Use of Color). The underline marks a link for everyone, whatever colours they can see.

daisyUI: components and a theme

New Tool: daisyUI

What problem exists? With utilities alone, every navigation bar or card repeats the same long list of classes, and the colours they use need names that every page shares.

What did people do before? They copied class lists between templates, or wrote component rules by hand and invented their own colour names.

What is daisyUI? A plugin for Tailwind, version 5.7.50 here. It adds component classes such as navbar, card, and btn, and themes: sets of colour variables with fixed role names, such as --color-primary. It is CSS only, with no JavaScript.

Why daisyUI? A short, readable vocabulary for common pieces, whose colours all come from the theme. Change a role’s value once, and every component that uses the role follows.

Now let’s use it.

We define one light theme named otahque, using the colours measured in Chapter 13. It is a proposal for this stage of the book, not a final brand. Table 14.3 lists its roles. The contrast ratios were calculated with the WCAG 2.2 formula; the requirement is at least 4.5:1 for normal text and at least 3:1 for a focus indicator against the colours beside it.

Table 14.3 — The proposed otahque theme’s colour roles
Role Value Used for Measured contrast
base-100 #ffffff Cards Text 15.13:1; links 6.31:1
base-200 #f4f6f9 Page background Text 13.97:1; links 5.83:1
base-300 #d5dde8 Card borders Decorative edge, 1.37:1 on white
base-content #1b2735 Body text See the two rows above
primary #0759ce Links and the focus outline 6.31:1 on cards; 5.83:1 on the page
primary-content #ffffff Text on primary (not used yet) 6.31:1 on primary
neutral #142b46 Navigation bar White text 14.35:1
neutral-content #ffffff Navigation text and its focus outline 14.35:1 on neutral

Two things are deliberately missing from the table. daisyUI has no role for keyboard focus, so focus stays an ordinary :focus-visible rule in our source: a 3-pixel outline in the primary colour, and white inside the navigation. And the orange of the Sample: label, #9d480c (6.24:1 on cards, 5.76:1 on the page), stays in its own rule, because only one element uses it. Figure 14.1 shows which part of each page takes which role.

On the left, five colour swatches with their role names and values: neutral, base-content, base-100 with base-300 for its border, base-200, and primary. Arrows lead to a sketch of the event list page on the right: neutral colours the navigation bar, base-content the heading and text, base-100 and base-300 the event card, base-200 the page behind the content, and primary the underlined event link. A note across the bottom says focus is its own rule, not a theme role: a 3-pixel primary outline, white on the navigation.
Figure 14.1 — Where each theme role appears on the event list.

Each theme variable also becomes a family of utilities. Because the theme defines --color-neutral, the class bg-neutral sets a navy background and text-neutral-content sets white text. Tailwind has its own way to define tokens, an @theme block, which also creates utilities; daisyUI’s theme does that job for our colours, so we do not need one yet. An ordinary CSS variable that you declare yourself can be used in a rule with var(), but it creates no utility class.

Layers decide which rule wins

Chapter 13’s cascade compared origin and importance, then specificity, then order. Cascade layers add a step before specificity: when two rules from the same stylesheet conflict, the one in the later layer wins, however specific the other is. Tailwind declares four layers in this order: theme, base, components, and utilities.

Preflight and our element rules, such as the one for a, go in base. Our own class rules, such as .sample-label, go in components. Utilities come last, so p-4 on an element beats a component’s padding. daisyUI places its components inside the utilities layer, in nested layers that sit beneath the plain utilities, so a utility still adjusts a daisyUI component, and a daisyUI component still beats a rule in our components layer.

Try it yourself

Our source has a { color: var(--color-primary); } in the base layer and .site-nav a { color: inherit; } in the components layer. The navigation’s text-neutral-content utility makes the nav element’s text white.

Que. 1 What colour are the navigation links, and which comparison decides it?

Flip to check your answerFold answer back

Answer. White. The components layer comes after the base layer, so .site-nav a wins before specificity is even compared. Its inherit takes the colour of the nav element, which the utility set to the neutral-content white.

Literal class names and source scanning

Tailwind does not run templates. It reads the text of the files its sources name, splits the text into words that could be class names, and writes a rule for each word it recognizes. Three consequences follow.

First, class names must appear whole. If a template writes class="bg-{{ role }}", the scanner sees bg- and role, neither of which is a class, so no rule is written; when the page renders bg-primary, there is no CSS for it. Choose between complete names instead, so each one appears in the file:

{% if featured %}border-primary
{% else %}border-base-300{% endif %}

Second, the scanner can find words that only look like classes. {% block %}, {% load static %}, and inline in our templates match real utilities named block, static, and inline, so the output has a few small rules that no element uses. They are harmless.

Third, we say exactly where to look. By default, Tailwind scans the whole project folder, which would include events/tests.py and its class-like strings. We switch that off with source(none) and name three folders with @source: the project templates, the events app’s templates, and its templatetags folder, because a filter can write class names in Python, as sample_label does.

Under the Hood: from source to browser

When you run the build, the compiler reads static/otahque/source.css. The @import "tailwindcss" line brings in Tailwind’s four layers and Preflight. @plugin "daisyui" loads daisyUI from node_modules, and the theme block becomes CSS variables. The compiler then scans each @source folder for words that could be classes, keeps every word it can generate a rule for, places each rule in its layer, and adds the rules we wrote ourselves. It writes the result to static/otahque/site.css, an ordinary stylesheet. From there the path is Chapter 13’s: the finder locates the file, the static tag writes its address, the development server sends it, and the browser applies it. Nothing from Tailwind runs while Django serves a page, and neither Django nor the browser can tell that a compiler was involved.

The whole route is in Figure 14.2, and Table 14.4 lists who is responsible for each part and how to prove it.

Five numbered steps. Step 1, the authored source.css and the templates, which we write; a dashed note says source.css is never linked from a page. Step 2, the Tailwind compiler, run with npm run build, reads both and loads daisyUI. Step 3, it writes the generated site.css, which is committed and never edited by hand. Step 4, Django’s finder and static tag find that file, as in Chapter 13. Step 5, the browser receives it with a 200 response and applies the rules.
Figure 14.2 — From the authored source to the browser.
Table 14.4 — Who is responsible for each part
Part Responsibility How to check it
static/otahque/source.css Imports, sources, theme, and our own rules; edited by hand Read it; no page links it
Templates Class names, written in full Template tests
Tailwind compiler (npm run build) Turns the source and class names into CSS Build output; search site.css
static/otahque/site.css Generated output, committed; never edited by hand Compiled-output test
Django finder and static tag Find the file and write its address findstatic and the link test
Browser Applies the rules Network and Styles panels, keyboard

In practice: keeping a small component vocabulary

Situation. As Otahque grows, someone adds a registration page and pastes a twelve-class button from a tutorial, with colours that are not in the theme.

Application. Keep a short, reviewed list of the components Otahque uses (here, the navigation bar, the card, and the sample label) and add to it deliberately. A proposed component is checked for contrast and keyboard focus before it is used, and its colours come from theme roles.

Consideration. daisyUI offers dozens of components. Using one because it exists adds styles to review and checks to run, for no reader need. A component library also does not make a page accessible on its own: the colours in our theme are ours to measure.

The rest of this chapter’s tools are versions of things you already know. The compiled file is a static file, the theme variables are CSS custom properties, and the build is a command with a lockfile behind it.

Prefer not to install Node.js?

Tailwind also publishes a standalone executable with the compiler built in, and daisyUI’s Django guide shows how to use it with daisyUI’s own files. We use npm because one lockfile then pins Tailwind and daisyUI together, and npm ci reproduces both. If you cannot install Node.js on your computer, use the Tailwind 4.3.4 standalone executable in a separate copy of the project. The committed site.css still lets Django run while you sort it out.

PAGE 002

How We Build It

Start from Chapter 13, in the directory containing manage.py, with your own .env, the locked environment, 16 passing tests, and the Chapter 13 work committed to your Git repository. We will change events/tests.py, .gitignore, templates/base.html, templates/includes/site_nav.html, events/templates/events/list.html, and events/templates/events/detail.html, and static/otahque/site.css becomes a generated file. We will add package.json, .node-version, and static/otahque/source.css, and npm will add package-lock.json and a node_modules folder. Settings, views, URLs, the home template, and the sample_label filter do not change. At the end, the same pages are built from a theme and a small vocabulary of classes.

The Custom Way

This illustration shows the drift a design system prevents; do not add it to the project:

.event-row {
  border: 1px solid #d5dde8;
  padding: 1rem;
}

.venue-card {
  border: 1px solid #d6dde8;
  padding: 16px;
}

.speaker-box {
  border: 1px solid #d5dde8;
  padding: 0.9rem;
}

Three pages later, the hand-grown sheet has three rules for the same card. One border colour is a typing slip away from the others, and the same space is written three ways. Changing the border colour means finding every copy, and nothing says which copies were meant to match. The approach below keeps Django’s static files exactly as they are, and adds a compiler, a theme that names each colour once, and a short vocabulary of classes.

The Django Way

Step 1: Write the tests first

Common Error: a class in the HTML is not proof of CSS

A template test can prove that a page contains class="navbar", but not that any CSS exists for it. If the compiler never saw the class, the browser receives a class with no rule. We need a second test that reads the compiled stylesheet, and the browser still has the last word on what loads.

Run the Chapter 13 tests first, beside manage.py, in PowerShell, a macOS shell, or Linux/WSL Bash, and confirm all 16 pass:

uv run python manage.py test events

Open events/tests.py. Add one import line at the top, below the docstring and directly above from unittest.mock import patch:

from pathlib import Path

Then add this class at the end of the file:

class DesignSystemTests(SimpleTestCase):
    """The navigation uses the design system navbar."""

    def test_navigation_uses_navbar(self):
        response = self.client.get('/')
        self.assertContains(
            response, '<nav class="site-nav navbar'
        )

    def test_stylesheet_defines_navbar(self):
        found = finders.find('otahque/site.css')
        css = Path(found).read_text(encoding='utf-8')
        self.assertTrue(
            '.navbar {' in css,
            'site.css has no .navbar rule',
        )

The first test is a template contract: the navigation keeps its site-nav hook and gains daisyUI’s navbar component class. The second asks the finder for the stylesheet, exactly as the development server will, reads the file, and checks that it contains a .navbar rule. It uses assertTrue with a short message rather than assertIn, whose failure message would print the whole stylesheet. Run the tests:

uv run python manage.py test events

Expected result, shortened with ... where lines are left out:

Found 18 test(s).
System check identified no issues (0 silenced).
FF................
...
FAIL: test_navigation_uses_navbar (events.tests...
...
AssertionError: False is not true : Couldn't find
'<nav class="site-nav navbar' in the following response
...
FAIL: test_stylesheet_defines_navbar (events.tests...
...
AssertionError: False is not true : site.css has no
.navbar rule
...
Ran 18 tests in ...

FAILED (failures=2)

Both messages are single lines, wrapped here to fit the page. The 16 Chapter 13 tests still pass. The navigation has no navbar class, and Chapter 13’s hand-written sheet has no .navbar rule: both are the failures we expect.

Step 2: Install Node.js and pin the build tools

Common Error: npm refused in Windows PowerShell

Windows PowerShell may refuse to run npm with npm : File C:\Program Files\nodejs\npm.ps1 cannot be loaded because running scripts is disabled on this system. The installer adds a small PowerShell script called npm.ps1, and Windows’ default execution policy blocks scripts. Type npm.cmd instead of npm in every command in this chapter, which needs no setting changed. Changing the policy for your account with Set-ExecutionPolicy -Scope CurrentUser RemoteSigned also works; read what it allows before you choose it.

Install Node.js 26.13.0, the newest long-term support release when this book was pinned. It comes with npm 11.20.0. The official files are at https://nodejs.org/dist/v26.13.0/.

  • Windows: download node-v26.13.0-x64.msi, run it with the default options, and then open a new PowerShell window so that it finds the new commands.
  • macOS: download node-v26.13.0.pkg and run it.
  • Linux and WSL: download node-v26.13.0-linux-x64.tar.xz, unpack it, and add its bin folder to your PATH; or, if you already use a Node version manager, ask it for exactly 26.13.0.

Check both versions, in any of the shells:

node --version
npm --version
v26.13.0
11.20.0

Common Error: moving versions and generated project files

Do not run npm install tailwindcss@latest: latest names whatever is newest on the day you run it, so two readers get different tools. Do not run npm init -y either, which writes a package.json with guessed fields, including a description copied from the README. And keep Node packages out of pyproject.toml; uv cannot install them.

Create package.json beside manage.py, typing it as shown:

{
  "name": "otahque",
  "private": true,
  "engines": {
    "node": "26.13.0"
  },
  "scripts": {
    "css": "tailwindcss -i static/otahque/source.css",
    "build": "npm run css -- -o static/otahque/site.css",
    "watch": "npm run build -- --watch"
  },
  "devDependencies": {
    "@tailwindcss/cli": "4.3.4",
    "daisyui": "5.7.50",
    "tailwindcss": "4.3.4"
  },
  "allowScripts": {
    "@parcel/watcher": false
  }
}

Read it from the top. private stops the project from ever being published to the npm registry by mistake. engines records the Node.js release we use. The three devDependencies are the compiler’s command-line tool, the compiler itself, and daisyUI, each at an exact version with no range in front of it. The scripts build on each other, so each line stays short: css runs the compiler on our source, build adds the output file, and watch adds --watch. The -- passes the words after it to the script being run.

allowScripts needs a word of its own. Some packages run a program while they install. One of the compiler’s helpers, @parcel/watcher, which notices file changes for --watch, has such a script, used only to build itself when no ready-made copy exists. Ready-made copies exist for Windows, macOS, and Linux, so the script is not needed. npm 11.20 asks a project to approve or deny each install script; the entry denies this one, and it is what npm install-scripts deny @parcel/watcher would write. Never approve a script you have not read about.

Create .node-version beside it, containing one line. Several Node version managers read this file:

26.13.0

Now install, so that npm creates the lockfile:

npm install
added 29 packages, and audited 36 packages in ...

8 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

npm may also mention that a newer npm exists; ignore it, because the pinned version is deliberate. npm wrote package-lock.json with the exact version and a checksum of every package, including the helpers the three tools need, and put the packages in node_modules. Then reproduce the install from the lockfile alone, as another computer would:

npm ci
added 29 packages, and audited 36 packages in ...

8 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

npm ci deletes node_modules and installs exactly what the lockfile records, and it refuses to run if package.json and the lockfile disagree. From now on, use it whenever you set up the project. No install-scripts warning appears, because allowScripts covers the only install script.

The node_modules folder is large and can be rebuilt at any time, so keep it out of Git. Add a blank line and these two lines at the end of .gitignore:

# Node packages, rebuilt from package-lock.json by npm ci
node_modules/

Check what Git sees:

git status --short
 M .gitignore
 M events/tests.py
?? .node-version
?? package-lock.json
?? package.json

node_modules/ is not listed. The tests are unchanged since Step 1: both still fail.

Step 3: Carry Chapter 13’s rules into the source, then build

Common Error: building before the rules are in the source, or following Tailwind 3

The build overwrites site.css. Run it before copying Chapter 13’s rules into the source, and those rules are gone from the output. And many tutorials still show Tailwind 3, with a tailwind.config.js file and @tailwind base; lines: Tailwind 4 configures everything in CSS, and a source made of those lines builds without an error into a file with almost nothing in it.

Create static/otahque/source.css. It holds everything Chapter 13’s sheet did, translated to use the theme, plus the setup lines that only the compiler reads:

/* Otahque styles: Tailwind compiles this into site.css */
@import "tailwindcss" source(none);
@source "../../templates";
@source "../../events/templates";
@source "../../events/templatetags";

@plugin "daisyui" {
  themes: false;
}

@plugin "daisyui/theme" {
  name: "otahque";
  default: true;
  color-scheme: light;
  --color-base-100: #ffffff;
  --color-base-200: #f4f6f9;
  --color-base-300: #d5dde8;
  --color-base-content: #1b2735;
  --color-primary: #0759ce;
  --color-primary-content: #ffffff;
  --color-neutral: #142b46;
  --color-neutral-content: #ffffff;
  --radius-box: 0.375rem;
  --border: 1px;
}

@layer base {
  body {
    min-height: 100vh;
    background-color: var(--color-base-200);
  }

  h1 {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.25;
  }

  h1,
  p,
  ul {
    margin-bottom: 1rem;
  }

  a {
    color: var(--color-primary);
    text-decoration: underline;
  }

  :focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
  }
}

@layer components {
  main {
    max-width: 44rem;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
  }

  .site-nav {
    background: var(--color-neutral);
    padding: 0.75rem 1rem;
  }

  .site-nav a {
    color: var(--color-neutral-content);
    font-weight: 600;
    margin-right: 1.25rem;
  }

  .site-nav :focus-visible {
    outline-color: var(--color-neutral-content);
  }

  .event-row,
  .event-empty {
    background: var(--color-base-100);
    border: 1px solid var(--color-base-300);
    border-radius: var(--radius-box);
    padding: 1rem;
    margin-bottom: 0.75rem;
  }

  .event-row a {
    font-weight: 600;
  }

  .sample-label {
    color: #9d480c;
    font-size: 0.85em;
    font-weight: 700;
  }
}

Read it in five parts. The first five lines import Tailwind with automatic scanning switched off, then name the three source folders, relative to this file. The daisyui plugin block loads the components with themes: false, so none of daisyUI’s own themes is included. The theme block defines otahque with the roles from Table 14.3, makes it the default, and sets the corner radius for boxes and the border width that daisyUI’s components use. The base layer restores what Preflight removed and what Chapter 13 relied on: the page colour, a heading size, spacing below headings, paragraphs, and lists, underlined links, and the focus outline. The components layer holds Chapter 13’s class rules, with each colour replaced by its role.

A few Chapter 13 declarations are not here because Preflight and daisyUI now provide them: the body’s zero margin, font, and line height, the text colour, and the list’s removed bullets and indent.

Build it:

npm run build

Expected result. npm first prints each script it runs, shortened here with ...:

> build
> npm run css -- -o static/otahque/site.css


> css
> tailwindcss -i static/otahque/source.css -o ...

≈ tailwindcss v4.3.4

/*! ... daisyUI 5.7.50 */
Done in ...

On screen, the line that starts > tailwindcss ends -o static/otahque/site.css, and daisyUI prints a small flower symbol where the last ... is. The compiler replaced Chapter 13’s sheet with its output. Check that Django still finds it:

uv run python manage.py findstatic otahque/site.css
Found 'otahque/site.css' here:
  ...\static\otahque\site.css

findstatic otahque/source.css finds the source too, because it lives in the same static folder. That is expected: the development server would send it if asked, but no page asks, because base.html links only site.css, and Chapter 13’s link test keeps it that way. Whether a deployment copies the source is a Chapter 63 decision.

Run the tests:

uv run python manage.py test events
Found 18 test(s).
System check identified no issues (0 silenced).
FF................
...
Ran 18 tests in ...

FAILED (failures=2)

Still two failures, and that is the lesson of this step. The stylesheet is now compiled, but no template contains navbar, so the compiler wrote no rule for it. Start the development server with uv run python manage.py runserver and open http://127.0.0.1:8000/events/ with the developer tools open and Disable cache ticked, as in Chapter 13. The page looks as it did at the end of Chapter 13, with a slightly smaller heading. Stop the server with Ctrl+C.

Step 4: Use utilities and components in the templates

Common Error: classes on elements the tests pin, or class names built from parts

Two earlier tests compare the navigation links and the detail heading as whole HTML elements, attributes included. A class added to one of them fails those tests, so put classes on the elements that wrap them, and style the links and heading from the source. And never build a class from parts, such as bg-{{ role }}: the compiler cannot see it.

Replace templates/includes/site_nav.html. The nav element gains the navbar component and four utilities; the links do not change:

<nav class="site-nav navbar gap-5 bg-neutral px-4
            text-neutral-content" aria-label="Site">
  <a href="{% url 'events:home' %}">Home</a>
  <a href="{% url 'events:list' %}">Events</a>
</nav>

A class attribute may continue on the next line, as here; the browser reads the line break as a space. Replace templates/base.html, where main gains the five utilities we read earlier:

{% load static %}
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport"
        content="width=device-width, initial-scale=1">
  <title>{% block title %}Otahque{% endblock %}</title>
  <link rel="stylesheet"
        href="{% static 'otahque/site.css' %}">
</head>
<body>
  {% include "includes/site_nav.html" %}
  <main class="mx-auto max-w-2xl space-y-4 px-4 pt-6 pb-12">
    {% block content %}{% endblock %}
  </main>
</body>
</html>

Replace events/templates/events/list.html. The list gains spacing between its items, and each row and the empty state become cards:

{% extends "base.html" %}
{% load event_labels %}

{% block title %}Sample events | Otahque{% endblock %}

{% block content %}
  <h1>Sample events</h1>
  <p>These fictional events are examples.</p>
  <ul class="event-list space-y-3">
    {% for event in events %}
      {% partialdef event-row inline %}
        <li class="event-row card border border-base-300
                   bg-base-100 p-4 font-semibold">
          <a href="{% url 'events:detail' event.id %}">
            {{ event.title|sample_label }}
          </a>
        </li>
      {% endpartialdef %}
    {% empty %}
      <li class="event-empty card border border-base-300
                 bg-base-100 p-4">No sample events yet.</li>
    {% endfor %}
  </ul>
{% endblock %}

Each card uses border border-base-300 rather than daisyUI’s card-border. That class draws its border in the base-200 colour, which in our theme is the page background, so the edge would vanish. Reading what a component actually sets, in its documentation or in the Styles panel, is part of choosing it.

Replace events/templates/events/detail.html. The heading and text become a card, and the back link moves into a paragraph below it. The <h1> itself keeps no class:

{% extends "base.html" %}
{% load event_labels %}

{% block title %}Sample event | Otahque{% endblock %}

{% block content %}
  <article class="card space-y-4 border border-base-300
                  bg-base-100 p-6">
    <h1>{{ title|sample_label }}</h1>
    <p>This fictional event is an example.</p>
  </article>
  <p>
    <a href="{% url 'events:list' %}">All sample events</a>
  </p>
{% endblock %}

The templates now do the layout, so the source can shrink. Replace static/otahque/source.css with its final version:

/* Otahque styles: Tailwind compiles this into site.css */
@import "tailwindcss" source(none);
@source "../../templates";
@source "../../events/templates";
@source "../../events/templatetags";

@plugin "daisyui" {
  themes: false;
}

@plugin "daisyui/theme" {
  name: "otahque";
  default: true;
  color-scheme: light;
  --color-base-100: #ffffff;
  --color-base-200: #f4f6f9;
  --color-base-300: #d5dde8;
  --color-base-content: #1b2735;
  --color-primary: #0759ce;
  --color-primary-content: #ffffff;
  --color-neutral: #142b46;
  --color-neutral-content: #ffffff;
  --radius-box: 0.375rem;
  --border: 1px;
}

@layer base {
  body {
    min-height: 100vh;
    background-color: var(--color-base-200);
  }

  h1 {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.25;
  }

  a {
    color: var(--color-primary);
    text-decoration: underline;
  }

  :focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
  }
}

@layer components {
  .site-nav a {
    color: inherit;
    font-weight: 600;
  }

  .site-nav :focus-visible {
    outline-color: currentColor;
  }

  .sample-label {
    color: #9d480c;
    font-size: 0.85em;
    font-weight: 700;
  }
}

Compared with Step 3, the spacing rule for headings, paragraphs, and lists has gone, because space-y-4 and space-y-3 now space the children of main, the article, and the list. The rules for main, the navigation bar, and the cards have gone too: their utilities and components are in the templates. The reading column is slightly narrower than before, because max-w-2xl is 42rem on Tailwind’s scale, where Chapter 13 wrote 44rem by hand. Three rules remain in our components layer, each about something only Otahque knows. Navigation links take the navigation’s text colour, the navigation’s focus outline takes the same colour, and the sample label keeps its orange.

Before building, run the tests once:

uv run python manage.py test events
Found 18 test(s).
System check identified no issues (0 silenced).
.F................
...
FAIL: test_stylesheet_defines_navbar (events.tests...
...
Ran 18 tests in ...

FAILED (failures=1)

The template test passes, but site.css is stale: it was built before any template said navbar. This is the most common surprise with a compiler. The fix is always to build, never to edit the output:

npm run build
uv run python manage.py test events
...
Found 18 test(s).
System check identified no issues (0 silenced).
..................
Ran 18 tests in ...

OK

All 18 pass, and none of the 16 Chapter 13 tests needed a change.

Step 5: Check the result in the browser

Common Error: editing the generated file, or forgetting the build

A change typed into site.css works until the next build overwrites it. Edit source.css or a template, then build. If a change does not appear, check that the build ran after the edit before suspecting the browser.

Start the development server again and open http://127.0.0.1:8000/events/, with the developer tools open and Disable cache ticked:

uv run python manage.py runserver

Check four things.

  • The file. In the Network panel, site.css loads with status 200. No request for source.css appears.
  • The rules. Right-click the sample event’s card and choose Inspect, then select its li element. The Styles panel lists .p-4 with padding, and .card with display: flex, both from site.css. Inspect a navigation link: .site-nav a sets color: inherit, and the base a rule’s colour below it is crossed out.
  • The keyboard. Click the address bar and press Tab. Focus moves to Home and Events, each with a white outline on the navy bar, then to the sample event with a blue outline. Every link is underlined, so none depends on colour alone.
  • Widths. In the device view, try widths of 320, 390, 768, and 1440 pixels on the home page, the list, and the detail page. The text fits without sideways scrolling, and the column stays centred on wide screens.

Open http://127.0.0.1:8000/events/999/. It returns a 404. That page is Django’s own debug page, not our layout, so it stays unstyled.

While you change styles, a watcher saves typing. Leave the server running, open a second terminal beside manage.py, and run:

npm run watch

It builds once and then waits. Each time you save the source or a template, it rebuilds and prints another Done in ...; reload the page to see the result. While it runs, the watcher only adds rules: if you remove a class from a template, its rule stays in site.css until the next one-off build. That is one reason the watcher is a development convenience only, and why Step 6 ends with npm run build. Stop it with Ctrl+C, and if Windows asks Terminate batch job (Y/N)?, answer Y. Then stop the server.

Step 6: Prove the build reproduces, then rerun everything

Common Error: committing output that does not match its source

If site.css was built before your last template edit, or still holds rules a watcher kept for classes you removed, the committed output and its source disagree, and the next person who builds gets a different file. Build once more before committing, and let Git confirm that a rebuild changes nothing.

With the watcher stopped, reinstall from the lockfile, build, and stage the output, so Git keeps a copy to compare against:

npm ci
npm run build
git add static/otahque/site.css

Now build again and ask Git whether the file changed:

npm run build
git diff --exit-code -- static/otahque/site.css

git diff prints nothing and exits with status 0: the second build wrote exactly the same bytes. Given the same lockfile, source, and templates, the build always does. Finally, run the checks once more:

uv run python manage.py check
uv run python manage.py test events
System check identified no issues (0 silenced).
Found 18 test(s).
System check identified no issues (0 silenced).
..................
Ran 18 tests in ...

OK

As before, do not apply migrations yet.

When something goes wrong

Table 14.5 lists the problems this chapter can produce. Most come from three places: the toolchain, the source, or the gap between the source and the output. Check them in that order.

Table 14.5 — Build and design problems and safe recovery
Symptom Possible cause What to check
npm : File ... npm.ps1 cannot be loaded because running scripts is disabled Windows PowerShell blocks the npm.ps1 script Type npm.cmd instead of npm
npm error The `npm ci` command can only install with an existing package-lock.json No lockfile yet Run npm install once, then npm ci; never delete the lock to silence an error
npm warn install-scripts ... not yet covered by allowScripts allowScripts is missing from package.json Compare package.json with the listing; do not approve a script unread
'tailwindcss' is not recognized as an internal or external command, or tailwindcss not found on macOS and Linux The packages are not installed Run npm ci beside manage.py
Error: Can't resolve 'daisyui' in ... The @plugin name is misspelled, or daisyUI is missing from package.json Compare the @plugin line and package.json with the listings, then run npm ci
Chapter 13's styles vanished after the first build The build ran before the rules were in source.css Copy the rules into source.css from Step 3, then build
Links look like plain text and headings like body text The base layer is missing, or the build did not run Search site.css for the base rules; add them, then build
A template class has no effect Its folder has no @source line, the name is built from parts, or another rule wins Search site.css for the class; read the Styles panel; do not reach for !important
An existing test fails after Step 4 A class went on a navigation link or the detail h1 Read the expected HTML in the failure; move the class to the wrapper
The page loses all styles base.html links source.css, or the output is empty View the page source; restore the site.css link and build
Focus is hard to see The focus rule was removed or overridden Tab through the page; restore the :focus-visible rules and build
npm run watch stops at once It was started without a normal terminal Run it in an ordinary terminal window
site.css keeps a rule for a class you removed The watcher only adds rules while it runs Stop the watcher and run npm run build
site.css has large unexpected changes The build ran from another folder, or a source line is too broad Read the @source lines; build again beside manage.py

Two of these need care. allowScripts exists so that you decide which install programs run; approving one to make a warning go away defeats it. And when the output looks wrong, the cure is in the source, the templates, or the toolchain, never in hand edits to site.css.

Keep your work while you diagnose a problem. Compare the one file a message names with its listing, and save a copy before replacing anything you want to keep. If Node.js cannot be installed at all, follow the standalone route from the “Prefer not to install Node.js?” note in a separate copy, and leave this project as it is. Do not delete the project or reset Git as a first response.

PAGE 003

Verify Your Work

Run the checks in Table 14.6 beside manage.py, with the development server running for the browser rows.

Table 14.6 — Verification checklist for Chapter 14
Check Command or action Expected result
Configuration uv run python manage.py check System check identified no issues (0 silenced).
Automated checks uv run python manage.py test events Found 18 test(s). and OK at the end
Design-system tests uv run python manage.py test events -k DesignSystem Found 2 test(s). and OK at the end
Pinned tools node --version and npm --version v26.13.0 and 11.20.0
Clean install npm ci added 29 packages, with no install-scripts warning
Build npm run build tailwindcss v4.3.4, daisyUI 5.7.50, then Done
Reproducible output Stage site.css, build again, then git diff --exit-code -- static/otahque/site.css No output
File found uv run python manage.py findstatic otahque/site.css Your project's static folder
Only the output is linked View the source of any page href="/static/otahque/site.css", and no source.css
File served Network panel on http://127.0.0.1:8000/events/ site.css with status 200
Rules applied Styles panel on the event card .card and .p-4 from site.css
Keyboard Press Tab from the address bar White outline on Home and Events, blue on the event link
Links Look at every page Every link underlined
Widths Device view at 320, 390, 768, and 1440 pixels No sideways scrolling
Contrast The pairs in Table 14.3 in a contrast checker At least 4.5:1 for text, 3:1 for focus
Missing event Open http://127.0.0.1:8000/events/999/ A 404 page

Each kind of check proves something different. The template test proves that the navigation carries the navbar class. The compiled-output test proves that the stylesheet Django finds has a rule for it. Neither proves that the browser received the file or that the page is readable: the Network, Styles, keyboard, and width rows do that, and the contrast row checks the theme’s colours rather than trusting the library. We checked these in Chromium on Windows; the same steps apply in Firefox and Safari, whose developer tools name things slightly differently.

These checks also complete the first milestone, M1. Soni opens the local site, sees a styled list of sample events, and opens one event’s detail page. The pages share the base layout and the compiled styles, an unknown event returns 404, the tests prove that HTML in a title is escaped, and the route, view, and template tests pass. When every row in Table 14.6 passes on your computer, you have reached M1.

The official references for this chapter are:

PAGE 004

Checkpoint: Quiz and Challenge

Quiz

Que. 2 What does npm ci do that npm install does not?

Flip to check your answerFold answer back

Answer. It installs exactly the versions in package-lock.json, starting from an empty node_modules, and it refuses to run if package.json and the lockfile disagree. npm install may update the lockfile. Use npm ci to reproduce a setup.

Que. 3 Why does the compiled stylesheet have no .navbar rule until a template uses the class?

Flip to check your answerFold answer back

Answer. Tailwind writes rules only for class names it finds in its sources. With source(none), those are the folders named by @source lines, and until a template there contains navbar, nothing asks for the rule.

Que. 4 Why do links need an underline as well as the primary colour?

Flip to check your answerFold answer back

Answer. Preflight removes the browser’s underline, and our link blue measures only 2.40:1 against the body text, below the 3:1 needed when colour alone marks a link. The underline marks links for everyone.

Que. 5 A template writes class="bg-{{ role }}", and role is primary. Why does the element have no background colour?

Flip to check your answerFold answer back

Answer. The compiler reads the template’s text, where bg-primary never appears whole, so it writes no rule for it. Choose between complete class names, such as {% if featured %}bg-primary{% else %}bg-base-100{% endif %}.

Que. 6 In which layer does a utility class sit, and what does that mean for a component’s padding?

Flip to check your answerFold answer back

Answer. In utilities, the last layer, so a utility such as p-4 on an element beats the padding a component sets. daisyUI’s components sit in nested layers beneath the plain utilities for that reason.

Mini-Challenge

Work in a separate copy of your project, so your checkpoint stays as it is.

Que. 7 In the copy, give the empty state a dashed border, so that “no events” never looks like an event. Write the tests first: one that the empty list renders the border-dashed class, and one that the compiled stylesheet has a rule for it.

Flip to check your answerFold answer back

Answer. Add this class at the end of events/tests.py in the copy. It uses patch, views, and finders, which the file already imports:

class EmptyStateTests(SimpleTestCase):
    """An empty list shows the dashed empty state."""

    def test_empty_state_is_dashed(self):
        with patch.dict(
            views.SAMPLE_EVENTS, {}, clear=True
        ):
            response = self.client.get('/events/')
        self.assertContains(response, 'border-dashed')

    def test_stylesheet_defines_dashed(self):
        found = finders.find('otahque/site.css')
        css = Path(found).read_text(encoding='utf-8')
        self.assertTrue(
            '.border-dashed {' in css,
            'site.css has no .border-dashed rule',
        )

Both fail. In the copy’s events/templates/events/list.html, replace the empty state’s two lines with these four:

      <li class="event-empty card border border-dashed
                 border-base-300 bg-base-100 p-4">
        No sample events yet.
      </li>

Run the tests: the template test passes and the stylesheet test still fails, because the output is stale. Run npm run build, and all 20 tests in the copy pass. border-dashed is a Tailwind utility, so it reaches the output only because a template contains it whole. Leave your main project at 18 tests for Chapter 15.

What We Learned

  • A design system is a small shared vocabulary of tokens, components, and rules that keeps pages consistent as they grow.
  • Node.js runs the build tools; npm pins them in package-lock.json and npm ci reproduces them, as uv does for Python.
  • Tailwind compiles an authored source and the class names in named templates into the ordinary site.css that Django serves.
  • Preflight resets browser defaults, so headings, links, and focus are restored on purpose in the base layer.
  • daisyUI adds components and a theme of named colour roles; their contrast is ours to measure.
  • Layers decide before specificity: base, then components, then utilities.
  • Class names must appear whole in the sources; a stale output is fixed by building, never by editing it.

Key terms

Use Table 14.7 to explain this chapter’s ideas in your own words.

Table 14.7 — Key terms from Chapter 14
Term Meaning in this chapter
Design system A small shared vocabulary of tokens, components, and rules.
Token A named design value, such as --color-primary.
Role What a token is for, such as primary or neutral, rather than how it looks.
Lockfile A record of the exact versions installed, such as package-lock.json.
Compiler A tool that turns an input into an output; here, source.css into site.css.
Utility class A class with one job, such as p-4.
Component class A class for a familiar piece, such as card.
Preflight Tailwind's reset of browser defaults.
Cascade layer A named group of rules; later layers win before specificity is compared.
Source scanning Reading named files for words that could be class names.

Readiness checkpoint: you are ready for Chapter 15 when npm ci and npm run build succeed, a second build changes nothing, all 18 tests pass, and every row of Table 14.6 passes in the browser. At that point you have reached M1. Explain why the compiled-output test cannot replace the browser checks. Return to the relevant part if any result is missing.

Git Commit

Check the changes, then stage the new and changed files, in PowerShell, a macOS shell, or Linux/WSL Bash, beside manage.py. The last command prints one line per staged file with the number of lines changed:

git status --short
git add .gitignore .node-version
git add package.json package-lock.json
git add static templates events
git diff --cached --stat

The list includes both static/otahque/source.css and the generated site.css, so the project runs without a build on a computer that has no Node.js. node_modules stays out, as do .env and .venv. Then record the commit:

git commit -m "Add the Tailwind and daisyUI build"
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 you to diagnose a problem in order. L4 and L5 look ahead to a larger application and to deployment: attempt them now, and return to them later. They are extension questions, not a gate to the next chapter. Run each code proof beside manage.py, in PowerShell, a macOS shell, or Linux/WSL Bash.

L1 (Junior): What does Tailwind compile, and why does Django still use the static tag?

What the interviewer is testing: Can you separate a build step from serving a page?

Flip to check your answerFold answer back

Perfect answer: Tailwind compiles one input stylesheet, together with the class names it finds in the files the input names, into an ordinary CSS file. It runs when a developer builds, not when someone requests a page. Django then treats that output like any other static file: the finder locates it and the {% static %} tag writes its address. The tag still matters because the address can change later, for example to a hashed file name or another server, without any template changing. Tailwind knows nothing about Django, and Django knows nothing about Tailwind.

Table 14.8 — The compiler’s job compared with Django’s
Question Tailwind compiler Django static files
When it runs When you build On each request in development
What it reads source.css and the named templates The built site.css
What it produces site.css The file's address and contents
Knows about the other No No

Behind the scenes:

read source.css; load tailwindcss and daisyui
scan each @source folder for class-like words
keep the words it can write a rule for
write the layers and our own rules to site.css

Code proof: the address the tag writes, and the file behind it:

uv run python manage.py shell -c "
from pathlib import Path
from django.contrib.staticfiles import finders
from django.templatetags.static import static
css = Path(finders.find('otahque/site.css')).read_text(
    encoding='utf-8')
print(static('otahque/site.css'))
print(css.startswith('/*! tailwindcss v4.3.4'))
"
12 objects imported automatically (use -v 2 for details).

/static/otahque/site.css
True

The address is the same as in Chapter 13, and the file behind it now starts with the compiler’s header.

Common mistakes:

  • Thinking Tailwind runs in the browser or on each request.
  • Linking source.css instead of the output.
  • Typing /static/... because “the build knows the path”.

Follow-up the interviewer might ask:

  • “What would change if site.css were served from another domain?”
  • “Why commit a generated file?”

L2 (Mid-Level): Trace a literal utility from a Django template to a rendered page.

What the interviewer is testing: Can you name each step between a class name and a styled element, and the check for each?

Flip to check your answerFold answer back
The class max-w-2xl is written whole in base.html, which an @source line names. The build scans it and writes a .max-w-2xl rule into site.css. Django renders the class into the page and serves site.css. The browser matches the class to the rule, which the Styles panel shows.
Figure 14.3 — Trace one utility from template to browser.

Perfect answer: Take max-w-2xl on the layout’s main. It is written whole in templates/base.html, a folder that an @source line names. When I build, the compiler scans that file, recognizes the word, and writes a .max-w-2xl rule with max-width into site.css. When a page is requested, Django renders the class into the HTML, and the static handler serves site.css. The browser matches the class selector to the element, and the Styles panel shows the rule and which file it came from. At each step there is a check: the template, a search of the output, the rendered HTML, and the browser.

Behind the scenes:

template text -> scanner finds max-w-2xl
compiler writes .max-w-2xl { max-width: ... }
Django renders class="... max-w-2xl ..."
browser matches the selector and applies it

Code proof: the class in the rendered page and its rule in the output:

uv run python manage.py shell -c "
from pathlib import Path
from django.contrib.staticfiles import finders
from django.template.loader import render_to_string
css = Path(finders.find('otahque/site.css')).read_text(
    encoding='utf-8')
page = render_to_string('events/home.html')
print('max-w-2xl' in page, '.max-w-2xl {' in css)
"
12 objects imported automatically (use -v 2 for details).

True True

Common mistakes:

  • Checking only the template, and assuming the rule exists.
  • Forgetting that the build must run after the template changes.
  • Looking for the class in source.css, where utilities never appear.

Follow-up the interviewer might ask:

  • “How would you find which file a rule in the Styles panel came from?”
  • “What happens to the trace if the template folder has no @source line?”

L3 (Senior): Why is a dynamically constructed class absent, and how should the template change?

What the interviewer is testing: Can you diagnose a missing rule from the scanner’s point of view, and fix the template rather than the output?

Flip to check your answerFold answer back
First confirm the class appears in the rendered HTML. Then search site.css for its rule. If the rule is missing, find the class in the template source and see whether it is written whole. If it is built from parts, rewrite it as a choice between complete class names, build again, and confirm the rule appears.
Figure 14.4 — Diagnose a class with no rule.

Perfect answer: The compiler never runs the template. It reads the template’s text, so bg-{{ role }} gives it bg- and role, and the finished name bg-primary exists only in the rendered page, after the build has finished. I would confirm it in order: the rendered HTML has the class, the output has no .bg-primary rule, and the template builds the name from parts. The fix is to write every possible name in full, as a choice in the template or a value from a small mapping written in a scanned file, then build. I would not add the rule to site.css by hand, and I would only list classes for the compiler to keep if a real case needed it.

Behind the scenes:

scanned text:  class="bg-{{ role }}"
words found:   class, bg-, role
rule written:  none
rendered HTML: class="bg-primary"   (no CSS for it)

Code proof: one theme utility used in a template, and one that only exists by name:

uv run python manage.py shell -c "
from pathlib import Path
from django.contrib.staticfiles import finders
css = Path(finders.find('otahque/site.css')).read_text(
    encoding='utf-8')
for name in ('bg-neutral', 'bg-primary'):
    print(name, '.' + name + ' {' in css)
"
12 objects imported automatically (use -v 2 for details).

bg-neutral True
bg-primary False

bg-primary is a valid class, and the theme defines primary, but no template contains the name whole, so the output has no rule for it.

Common mistakes:

  • Editing site.css to add the missing rule.
  • Assuming that a valid class name is always in the output.
  • Scanning the whole project to catch it, which adds noise instead of fixing the template.

Follow-up the interviewer might ask:

  • “Where should a mapping from event status to class name live?”
  • “When is listing classes for the compiler to keep justified?”

L4 (Staff): When should a value become an Otahque token rather than a one-off utility?

What the interviewer is testing: Can you decide what belongs in the design system, and keep the system small?

Flip to check your answerFold answer back
First ask whether the value is spacing or layout. If it is, use Tailwind’s existing utility scale and add no token. If not, ask whether it carries a meaning that several places share, such as the primary action colour. If it does, measure its contrast and focus against every colour it meets, then add a theme role and record the decision. If it does not, keep the value in that one component’s rule until a second use appears.
Figure 14.5 — Decide where a value belongs.

Perfect answer: A value becomes a token when it carries a meaning that more than one place must share, so that changing it should change all of them together. The link and focus blue is a good example: it is the primary role, used by links and the focus outline. A value used in one place, such as the sample label’s orange, stays in that component’s rule until a second use appears; promoting it early adds a name nobody needs. Spacing and layout use Tailwind’s existing scale rather than new tokens. Before a new role goes in, I would check its contrast against the colours it sits on, and I would record the decision, because a theme is a shared contract, not a palette.

Behind the scenes:

spacing and layout            -> the utility scale
shared meaning, several uses  -> theme role (--color-...)
one component, one use        -> that component's rule

Code proof: how often the output uses the primary role, and the label’s orange:

uv run python manage.py shell -c "
from pathlib import Path
from django.contrib.staticfiles import finders
css = Path(finders.find('otahque/site.css')).read_text(
    encoding='utf-8')
print(css.count('var(--color-primary)'))
print(css.count('#9d480c'))
"
12 objects imported automatically (use -v 2 for details).

2
1

The primary role reaches two rules, links and focus, through one variable, so changing it changes both together. The orange appears once, in the one rule that needs it.

Common mistakes:

  • Turning every colour into a token, so the theme becomes a list nobody reads.
  • Keeping a shared colour as repeated values, so changes miss copies.
  • Adding a role without measuring its contrast.

Follow-up the interviewer might ask:

  • “What would justify a second theme, such as a dark one?”
  • “How would you review a proposed new component?”

L5 (Lead): How would you keep the CSS build reproducible and prepare it for deployment?

What the interviewer is testing: Can you separate a reproducible build from a development watcher and from a deployment design?

Flip to check your answerFold answer back
Pin exact versions in package.json and the lockfile. Install with npm ci. Build once with npm run build, not the watcher. Confirm a second build changes nothing and commit the output with its source. At deployment, collect the built file with collectstatic, give it a hashed name and long cache times, and verify the deployed pages.
Figure 14.6 — From a pinned build to a deployment plan.

Perfect answer: I would pin exact versions in package.json, keep package-lock.json in Git, and install with npm ci everywhere, so every developer and any automated check runs the same compiler. The watcher is for editing only, and it never removes a rule while it runs; a release uses the one-off build. Because a build from the same inputs is byte-identical, a check can rebuild and fail if the committed site.css differs, which catches stale output. For deployment I would keep the templates and the {% static %} tag, run collectstatic so that the built file is copied with a hashed name, serve it with long cache times, and verify the deployed pages. Whether the source file is collected too, and whether the output is minified, are decisions for that design. Otahque makes them in Chapter 63, where they can be run and checked.

Behind the scenes:

npm ci                -> exact tools from the lockfile
npm run build         -> site.css from source and templates
rebuild + git diff    -> committed output is current
collectstatic         -> hashed copy for the server (Ch. 63)

Code proof: the pins in package.json agree with the lockfile:

uv run python -c "
import json
pkg = json.load(open('package.json'))
lock = json.load(open('package-lock.json'))
for name, pin in pkg['devDependencies'].items():
    got = lock['packages']['node_modules/' + name]['version']
    print(name, pin, got)
"
@tailwindcss/cli 4.3.4 4.3.4
daisyui 5.7.50 5.7.50
tailwindcss 4.3.4 4.3.4

Every exact pin matches what the lockfile installed, so npm ci gives every computer the same three tools.

Common mistakes:

  • Running the watcher on a server, or treating it as the build.
  • Pinning with ranges or latest, so builds drift.
  • Committing output that a rebuild would change.

Follow-up the interviewer might ask:

  • “How would an automated check catch a stale site.css?”
  • “Should the server run Node.js at all?”

Next: Chapter 15 introduces relational databases and Otahque’s first entity-relationship diagram.

PAGE 006