About Sitemap Pagination

You can paginate the items in your sitemaps by setting the limit attribute in the Sitemap class. The sitemap index will list out the URLs of paginated sitemaps.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# urls.py
from django.urls import path
from django.contrib.sitemaps import GenericSitemap
from django.contrib.sitemaps import views as sitemaps_views

from myapp.models import Item

info_dict = {
    "queryset": Item.objects.published(),
    "date_field": "modified",
}

class PaginatedSitemap(GenericSitemap):
    limit = 50

sitemaps = {"items": PaginatedSitemap(info_dict, priority=1.0)}

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"
    ),
]

Tips and Tricks Programming Architecture Development Search Engine Optimization Django 4.2 Django 3.2 Django 2.2