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.

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. The
    # request argument is necessary because Django's sitemaps
    # depend on django.contrib.sites, resp. RequestSite.
    sitemap.add_django_sitemap(PagesSitemap, request=request)

    # 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,
    )

URLconf:

from app.views import sitemap

urlpatterns = [
    url(r'^sitemap\.xml', sitemap),
    ...
]

Project details


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-1.0.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

django_sitemaps-1.0.1-py2.py3-none-any.whl (5.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-sitemaps-1.0.1.tar.gz.

File metadata

File hashes

Hashes for django-sitemaps-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b7fd84cfdd757d20d8dd7b1471f6afec95889e64ede4dad63c50d84e82c3d0ac
MD5 6c3d29fbe044fb71fedd2981ce18a618
BLAKE2b-256 85a6ac12c0ff9079aa2d57893bab799eba4a8060ae1dcef962dbb83ba1cf2862

See more details on using hashes here.

File details

Details for the file django_sitemaps-1.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_sitemaps-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 aba4481d6ba308e8bbfc1240c3f60c7e4c104399506342c6acb9a04a6677b643
MD5 ef0f8c877919e684d2a106f890d43dc1
BLAKE2b-256 84c362e985efd99288aa47defd90f334c2805c75f7ab7534b79cf8a303505f8c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page