liveBook · Manning

Static site generator

As explained in Django in Action

A site generator is a tool that produces deployable website files from source content, templates, or application data.

A static site generator turns source pages and reusable components into website files. Each URL can map directly to a file on the server, avoiding database queries and making the result easy to cache. This is useful when a dynamic site would be overkill but consistent templates, such as a shared navigation bar, still matter. section 13.5

Django Distill applies this idea to a Django project. Install it with python -m pip install django-distill, add django_distill to INSTALLED_APPS, and replace path() with distill_path() in urls.py. The replacement preserves normal site behavior while adding a management command that writes static versions of mapped URLs; each distill_path() call also names the file to generate. section 13.5

A generator is especially helpful when:

  • The site mostly serves fixed pages and does not need the overhead of a dynamic database-backed request. section 13.5
  • Pages need reusable templates or components instead of manually maintained copies of shared elements. section 13.5
  • A Django template engine is desirable, but serving generated HTML is preferable to hosting the complete Django site. section 1.2.3

A small recipe site

A family recipe site can store recipes in data files and use a simple view to render them as HTML. If one person edits the content, a content management system may be unnecessary; generating a static site keeps the Django-based rendering approach while avoiding a hosted dynamic application. section 13.5

How Django in Action covers it

How deep it goes
Explains composition, caching, installation, URL replacement, and file generation, but does not detail generated-file hosting.
Examples
Uses a family recipe site whose data files feed a simple HTML-rendering view.
What it assumes
Assumes familiarity with Django projects, templates, and urls.py while explaining the static-site motivation from the beginning.
What you can do after
Operate/configure Django Distill by installing it, registering the app, replacing path(), and generating mapped static URLs.
How it connects
Connects static websites with reusable components, Django, URL routing, templates, database queries, and caching.

Also explained in

Compare how 2 books explain static site generator →

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.