django-sitemaps
sitemap.xml generation using lxml with support for alternates. It uses Python 3’s keyword-only arguments for self-documenting code.
Why not django.contrib.sitemaps?
Django’s sitemaps framework didn’t support alternates when this package was written. Django 3.2 added i18n, languages and alternates, but alternate URLs are still derived by activating each language and reversing the same object’s URL. django-sitemaps instead lets you pass arbitrary alternate URLs for each entry, e.g. when languages live on different domains. URLs are added one-by-one from a regular view, without having to write Sitemap classes. Existing Django sitemaps can still be included using add_django_sitemap.
Installation
Simply pip install django-sitemaps. The package consists of a single python module, django_sitemaps, containing the single class; there’s no additional configuration necessary.
Usage
View:
from app.pages.sitemaps import PagesSitemap
def sitemap(request):
sitemap = Sitemap(
# All URLs are passed through build_absolute_uri.
build_absolute_uri=request.build_absolute_uri,
)
# URLs can be added one-by-one. The only required argument
# is the URL. All other arguments are keyword-only arguments.
for p in Page.objects.active():
url = p.get_absolute_url()
sitemap.add(
url,
changefreq='weekly',
priority=0.5,
lastmod=p.modification_date,
alternates={
code: urljoin(domain, url)
for code, domain in PAGE_DOMAINS[p.language].items()
},
)
# Adding conventional Django sitemaps is supported. Pass either
# the class or an instance. Their URLs are also passed through
# build_absolute_uri, so django.contrib.sites isn't required.
sitemap.add_django_sitemap(PagesSitemap)
# You could get the serialized XML...
# ... = sitemap.serialize([pretty_print=False])
# ... or use the ``response`` helper to return a
# ready-made ``HttpResponse``:
return sitemap.response(
# pretty_print is False by default
pretty_print=settings.DEBUG,
)
Some browsers display the sitemap as plain text because the xhtml:link alternates use a different namespace and no stylesheet is attached. The response is still valid XML served as application/xml; search engines don’t mind.
URLconf:
from django.urls import path
from django_sitemaps import robots_txt
from app.views import sitemap
urlpatterns = [
path('sitemap.xml', sitemap),
path('robots.txt', robots_txt(timeout=86400)),
...
]
The robots_txt function returns a view which can be used to generate a robots.txt file containing sitemap URLs. The default sitemap only contains:
User-agent: * Sitemap: <protocol>://<host>/sitemap.xml
The list of sitemap URLs may be overridden by setting sitemaps:
from django.urls import reverse_lazy
urlpatterns = [
path('robots.txt', robots_txt(
timeout=86400,
sitemaps=[
'/sitemap.xml',
reverse_lazy('articles-sitemap'),
...,
],
)),
]
Metadata
Release files for django-sitemaps 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_sitemaps-2.1.0.tar.gz | 5.1 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_sitemaps-2.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.1 kB
Release files / django_sitemaps-2.1.0.tar.gz
| Download URL | django_sitemaps-2.1.0.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7fa875774345fdd469c2a20f94e6269c48f21e7ef969911f1762f2ba18e3b8c
|
|
BLAKE2b-256 checksum How to use checksums |
3efdc1171bd96cad60e927f1d43e25dcead00239ef2daaf58a16c0eda8e75a17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.
Transparency logRelease files / django_sitemaps-2.1.0-py3-none-any.whl
| Download URL | django_sitemaps-2.1.0-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0d00a70f006eb4a77e6cf6acb5a41aacdfa5f6f220dd42cdb1526513b457b1aa
|
|
BLAKE2b-256 checksum How to use checksums |
5f2b559c5b07d50eaa113ee01ec77872e84e8939f153fb81378d65205054b34e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.
Transparency logSecurity for django-sitemaps 2.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for django_sitemaps-2.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.