[Django]-Decorating a sitemap view in Django

0👍

I am caching my sitemap by creating a view function and returning the built-in django sitemap view:

from django.views.decorators.cache import cache_page
from django.contrib.sitemaps.views import sitemap


@cache_page(60*60*1)
def sitemap_view(request):
    return sitemap(request, sitemaps)

urlpatterns = [
    path('sitemap.xml', sitemap_view, name='django.contrib.sitemaps.views.sitemap')
]

Leave a comment