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.
# 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 (SEO) Django 5.2 Django 4.2 Django 3.2
Django/Python Consulting
If you have a specific Django challenge or integration you'd like to solve, I'd be happy to help. Book a free 30-minute call to discuss your project, see if we're a good fit, and explore the best approach for your needs. After the call, you'll receive a tailored cost estimate based on what we discuss.
Also by me
Django Messaging
For Django-based social platforms.
Django Paddle Subscriptions
For Django-based SaaS projects.
Django GDPR Cookie Consent
For Django websites that use cookies.