Pytech Resources

Creating XML sitemaps for your Wagtail website

Nov 2, 2024

Posted by:

Sitemap for Wagtail website.

This is the first part of a three part article that explains how to create XML sitemaps for a Wagtail website for 3 different scenarios :

  1. Part 1, this blog, for just the Wagtail pages, using the Wagtail sitemap generator
  2. Part 2. Add Django static views in wagtail sitemap with lastmod entry
  3. Part 3. Forthcoming. Where the paths involve named regular expression groups (?P<name>pattern)

For just wagtail pages, the process of creating the sitemap is well-documented in Sitemap generator.

First step is to add "django.contrib.sitemaps" to INSTALLED_APPS in your Django settings file:

1
2
3
4
5
6
INSTALLED_APPS = [
...

"django.contrib.sitemaps",

]

Then in your project urls.py import the sitemap view from wagtail.contrib.sitemaps.views :

urls.py
1
2
3
4
5
6
7
8
from wagtail.contrib.sitemaps.views import sitemap

urlpatterns = [
    ...

    path('sitemap.xml', sitemap),

]

Make sure that the path('sitemap.xml') line is placed before the default Wagtail page serving route path("", include(wagtail_urls)).

Browse to /sitemap.xml to check that the sitemap is working. By default all published pages are added to the sitemap.