A set of helpers for baking your Django site out as flat files
Why and what for¶
The code documented here is intended to make it easier to save every page generated by a database-backed site as a flat file so you can host them using a static file service like Amazon S3.
At the Los Angeles Times Data Desk, we call this process “baking.” It’s our path to cheap, stable hosting for simple sites. We’ve used it for publishing election results, timelines, documents, interactive tables, special projects and numerous other things.
The system comes with some major advantages, like:
- No database crashes
- Zero server configuration and upkeep
- No need to optimize your app code
- You don’t pay to host CPUs, only bandwidth
- An offline administration panel is more secure
- Less stress (This one can change your life)
There are drawbacks. For one, you have to integrate the “bakery” into your code base. More important, a flat site can only be so complex. No online database means your site is all read and no write, which means no user-generated content and no complex searches.
Django’s class-based views are at the heart of our approach. Putting all the pieces together is a little tricky at first, particularly if you haven’t studied the Django source code or lack experience working with Python classes in general. But once you figure it out, you can do all kinds of crazy things: Like configuring Django to bake out your entire site with a single command.
- Getting started
- Buildable views
- Buildable models
- Settings variables
- Management commands
If you are seeking to “bake” out a very simple site, maybe you don’t have a database or only a single page, it is quicker to try Tarbell or Frozen-Flask, which don’t require all the overhead of a full Django installation.
This library is better to suited for projects that require a database, want to take advantage of other Django features (like the administration panel) or require more complex views.