Skip to main content

Wagtail Freezer

Generates static HTML sites from a Wagtail project

License

PyPI version wagtail-freezer CI

Links

Supported versions

  • Python 3.7 - 3.10
  • Django 3.2 - 4.0
  • Wagtail 3.x

Installation

  • pip install wagtail-freezer

  • Add "wagtail_freezer" to INSTALLED_APPS

  • Add a FREEZER_BUILD_DIR setting indicating where the static files will be output. To write into a folder named build at the project root, use:

    FREEZER_BUILD_DIR = os.path.join(BASE_DIR, "build")
    

Usage

Run ./manage.py buildstaticsite. This will generate one folder per site within FREEZER_BUILD_DIR, with subfolders making up the page tree and the pages themselves saved as index.html at the appropriate point.

While building the static files, wagtail-freezer will scan the HTML for any href or src attributes that reference files under STATIC_URL or MEDIA_URL, and copy these files to corresponding folders under the site root. This step only takes place if STATIC_URL or MEDIA_URL are local URLs beginning with '/'.

If you have additional static / media files that can't be found by parsing HTML (for example, images referenced within CSS, JavaScript or JSON), you can provide a freezer_follow_urls method on the page model that returns a list of media / static URLs to be followed:

class HomePage(Page):
    @property
    def freezer_follow_urls(self):
        urls = ['/static/images/background.jpg']
        for item in self.playlist.select_related('video'):
            urls.append(item.video.url)
        return urls

Deploying

When you're happy with how the local static site works (test it by running python -m http.server from the root folder), you can deploy it to Amazon S3 by installing the AWS command line tool (pip install awscli), creating a bucket configured for static website hosting, and running:

aws s3 sync build/localhost s3://mysite.example.com/ --acl public-read

Limitations

wagtail-freezer was created as a "minimum viable product" substitute for static site generators such as django-bakery, which at the time of writing are lagging behind in support for current Django (and Wagtail) versions. It has only been tested against very simple sites, and will probably not work with custom URL routes (RoutablePageMixin), pages with multiple preview modes (wagtail.contrib.forms, although that's not too usable on a static site anyhow), non-standard middlewares and no doubt lots of other things. Use at your own risk!

Release files for wagtail-freezer 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wagtail-freezer 0.1.0
File Size Uploaded
wagtail-freezer-0.1.0.tar.gz 12.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wagtail-freezer 0.1.0
File Interpreter ABI Platform
wagtail_freezer-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.5 kB

Release files / wagtail-freezer-0.1.0.tar.gz

Download URL wagtail-freezer-0.1.0.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e894f3fd2b45c720f0c7fcfc670082919152fe0d4eb23716c9e0c7a228969b91
BLAKE2b-256 checksum
How to use checksums
6d0c853a1f11463708502469a183d68076ebc9a268baeaca33059bf823ddd5d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release files / wagtail_freezer-0.1.0-py3-none-any.whl

Download URL wagtail_freezer-0.1.0-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1c111f64fcffa47664898e22f7e4e5fef7e1fe11592f66bce0dda15be05c5c6d
BLAKE2b-256 checksum
How to use checksums
be22ea865f78a5448b63802dcfb4335b738bdbf44342ca539234102ba03acab0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page