Skip to main content

No project description provided

Project description

sitemap.xml generation using lxml with support for alternates. It uses Python 3’s keyword-only arguments for self-documenting code.


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.



from app.pages.sitemaps import PagesSitemap

def sitemap(request):
    sitemap = Sitemap(
        # All URLs are passed through 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
        url = p.get_absolute_url()
                code: urljoin(domain, url)
                for code, domain in PAGE_DOMAINS[p.language].items()

    # Adding conventional Django sitemaps is supported. The
    # request argument is necessary because Django's sitemaps
    # depend on django.contrib.sites, resp. RequestSite.
    sitemap.add_django_sitemap(PagesSitemap, request=request)

    # You can also specify the site and protocol manually should you wish
    # to do so:
        PagesSitemap,, protocol=request.scheme
    # Note! If you're omitting the request you *have* to specify site and
    # protocol yourself.

    # 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


from django_sitemaps import robots_txt
from app.views import sitemap

urlpatterns = [
    url(r'^sitemap\.xml$', sitemap),
    url(r'^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 = [
    url(r'^robots\.txt$', robots_txt(

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_sitemaps-2.0.0.tar.gz (4.8 kB view hashes)

Uploaded source

Built Distribution

django_sitemaps-2.0.0-py3-none-any.whl (5.0 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page