liveBook · Manning

Django-distill

As explained in Django in Action

django-distill is a Django library that renders selected project URLs into static website files.

django-distill turns selected Django URLs into files for a static website. It suits sites where a full dynamic deployment is unnecessary but Django templates, reusable navigation, and familiar project conventions remain useful. Static files need no extra database queries when served and are easy to cache. section 13.5 section 1.2.3

A static site generator combines templates and reusable page components, then writes the resulting pages as files. django-distill keeps that workflow inside a Django project, so templates can provide a consistent look without learning another generator’s syntax. section 13.5 section 13.6

Install the library with `python -m pip install django-distill`, then add `django_distill` to `INSTALLED_APPS`. In URL configuration, replace `path()` for pages to be generated with `distill_path()`. The replacement preserves normal site behavior while recording enough information to generate a file for each mapped view. section 13.5

Each distilled route adds one important piece beyond an ordinary Django route:

  • Use `distill_path()` instead of `path()` for a URL that should become static output. section 13.5
  • Provide the filename that should be generated for the view, in addition to the usual route information. section 13.5
  • Run the provided management command to output static versions of URLs mapped by Distill. section 13.5

The result is a subset of a Django project whose URLs map directly to served files. This is useful when content changes infrequently and the project benefits more from simple static hosting than from a running Django service. section 13.6 section 13.5

Recipe site

A family recipe collection can keep recipes in data files and render them through a simple Django view. Distill can generate HTML for every recipe, leaving a static site that can be hosted by packaging and sending the generated files to a server. section 13.5

How Django in Action covers it

How deep it goes
Explains installation, app configuration, route replacement, filename output, and the generation command without detailing command internals.
Examples
Illustrates a family recipe site rendered from data files and exported as static HTML.
What it assumes
Assumes a Django project with URLs, views, and templates, while introducing Distill’s installation and routing changes.
What you can do after
Operate/configure it by marking Django routes with distill_path() and generating their static files.
How it connects
Connects Django URL routing, templates, views, static site generators, caching, and static hosting.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.