Nov 2, 2024
Posted by:
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 :
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.