Skip to main content

Modern Python Web Frontends Without React

This tutorial introduces the basics of four frontend tools: HTMX, Alpine.js, Tailwind and Playwright. They all work alongside a normal server-rendered web app, so you don’t need React or a JavaScript build step.

The slides for this tutorial are also available.

The main tools

HTMX

HTMX lets HTML elements make requests to the server and swap the response into the page. You add attributes like hx-post, hx-trigger, hx-target and hx-swap to your HTML, and the server sends back HTML fragments.

We use it to save checkbox changes to the database and to re-render todo items and the todo list without a full page reload.

Alpine.js

Alpine.js adds small bits of behaviour that happen entirely in the browser. You add attributes like x-data, x-on:click and x-show to your HTML.

We use it to show and hide each todo item’s description.

Tailwind CSS

Tailwind CSS is a CSS framework made of small utility classes, like font-bold, text-gray-400 and line-through. You style elements by adding classes directly in your HTML.

We load it straight from a CDN, so there is nothing to install or build.

Playwright

Playwright is a browser automation tool. It drives a real browser so you can write tests that click on things and check what the user sees.

We use it through the pytest-playwright plugin to test the features we build.

Supporting tools

These are already set up in the project. You don’t need to know them well to follow along.

  • Django: the Python web framework that serves our pages and HTML fragments.
  • SQLite: the database where our todos are stored.
  • uv: manages the Python version, virtual environment and dependencies.
  • pytest and pytest-django: run our tests.
  • django-browser-reload: refreshes the browser automatically when you change a template or Python file.