Wagtail

Tip

To log into the admin interface for our Wagtail sites, append /cms/ e.g. https://www.hatherleigh.info/cms/

Configuration

  1. Start by creating a home page.

  2. Browse to Settings, Sites and delete the default site.

  3. Create a new site and set the Root page to the home page you created in step 1.

Issues

Child Pages (e.g. Contact Us)

If you create a child page and it doesn’t appear in the menu:

  • Edit the page and click on the Promote tab.

  • Tick Show in menus - For site menus.

Sites - Home Page

Tip

When running the development server, the home page may not display. To fix this, Settings, Sites and tick Is default site.

_images/2024-03-25-is-default-site.png

For more information, Django Wagtail page not found when i don’t use “127.0.0.1:8000”:

Check the site records under Settings -> Sites in the Wagtail admin. When a request comes in, Wagtail will only serve a page if the hostname matches one named in a site record, or the ‘is default site’ box is checked.

404

Tip

If the page fails to display (probably a 404 Page Not Found error), then try publishing the page again.

Documents

We use SENDFILE for documents…

settings/production.py:

# https://docs.wagtail.io/en/stable/reference/settings.html#documents
WAGTAILDOCS_SERVE_METHOD = "direct"

Note

Really not sure what to do with WAGTAILDOCS_SERVE_METHOD. I tried to use serve_view with django-sendfile and couldn’t get it to work.

Domain

This is the base URL used by the Wagtail admin site:

# settings/local.py
WAGTAILADMIN_BASE_URL = "http://localhost:8000/"
# settings/production.py
WAGTAILADMIN_BASE_URL = DOMAIN

Home

If your Django project is looking for project.home, then try this:

from django.views.generic import RedirectView

url(
    r"^project/home/redirect/$",
    view=RedirectView.as_view(url="/", permanent=False),
    name="project.home",
),

To get the home page and site menu:

class MenuContext:
    def get_context(self, request):
        context = super().get_context(request)
        context["home_page"] = self.get_root()
        context["site_menu"] = self.get_children().live().in_menu()
        return context

# class ContactPage(MenuContext, Page):
#    ...
#
# class DefaultPage(MenuContext, Page):
#    ...

Editor Guide

A guide to using the Editor is here https://guide.wagtail.org/en-latest/

Tip

You can also access the guide through the CMS navigation bar. Go to Help > Editor Guide