I'm using wagtail app in my Django project. Is it possible to join django sitemaps (https://docs.djangoproject.com/en/1.11/ref/contrib/sitemaps/) with wagtail sitemaps (wagtail.contrib.wagtailsitemaps)? Tried using django sitemap indexes, but it divide only django sitemap, how I can include wagtail sitemap?
Wagtail uses the Django sitemap framework since version 1.10. This should allow you to easily combine regular Django sitemaps with Wagtail sitemaps.
There is a small catch however; because wagtail supports multiple sites the sitemap should know for which site the sitemap is generated. For this reason wagtail provides it's own sitemap views (index and sitemap). These views extend the Django sitemap views in order to propagate the site object.
So instead of importing the sitemap views from django:
from django.contrib.sitemaps import views as sitemap_views
Use the wagtail versions:
from wagtail.contrib.wagtailsitemaps import views as sitemaps_views
And then use the Django approach to map the urls to the views:
from wagtail.contrib.wagtailsitemaps import Sitemap
urlpatterns = [
# ...
url(r'^sitemap\.xml$', sitemaps_views.index, {
'sitemaps': {
'pages': Sitemap
},
'sitemap_url_name': 'sitemap',
}),
url(r'^sitemap-(?P<section>.+)\.xml$', sitemaps_views.sitemap,
name='sitemap'),
# ...
]
For a complete example you can see the code in the tests:
https://github.com/wagtail/wagtail/blob/911009473bc51e30ff751fda0ea5d2fa1d2b450f/wagtail/tests/urls.py#L36
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With