Django.fun

Django: How do I use a custom template for a specific sitemap only if I have multiple separate sitemaps?

I want to use a custom template only for a VideoSitemap when I have multiple sitemaps divided as follows: How can I use a custom template only for a specific sitemap?

I want to use a custom template for VideoSitemap with a sitemap tag for Video.

class VideoSitemap(Sitemap):
    changefreq = "weekly"

    def items(self):
        return Video.objects.published()

    def location(self, obj):
        return f"/video/{obj.pk}"

    def lastmod(self, obj):
        return obj.updated_at


class PlaylistSitemap(Sitemap):
    ...


class TagSitemap(Sitemap):
    ...

# urls.py
sitemaps = {
    "video": VideoSitemap,
    "playlist": PlaylistSitemap,
    "tag": TagSitemap
}

urlpatterns = [
    path(
        "sitemap.xml",
        sitemaps_views.index,
        {"sitemaps": sitemaps},
        name="django.contrib.sitemaps.views.index",
    ),
    path(
        "sitemap-<section>.xml",
        sitemaps_views.sitemap,
        {"sitemaps": sitemaps},
        name="django.contrib.sitemaps.views.sitemap",
    ),
]

Answers: 0