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
Release history Release notifications | RSS feed
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)
Built Distribution
File details
Details for the file django-sitemaps-1.0.1.tar.gz
.
File metadata
- Download URL: django-sitemaps-1.0.1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7fd84cfdd757d20d8dd7b1471f6afec95889e64ede4dad63c50d84e82c3d0ac |
|
MD5 | 6c3d29fbe044fb71fedd2981ce18a618 |
|
BLAKE2b-256 | 85a6ac12c0ff9079aa2d57893bab799eba4a8060ae1dcef962dbb83ba1cf2862 |
File details
Details for the file django_sitemaps-1.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: django_sitemaps-1.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aba4481d6ba308e8bbfc1240c3f60c7e4c104399506342c6acb9a04a6677b643 |
|
MD5 | ef0f8c877919e684d2a106f890d43dc1 |
|
BLAKE2b-256 | 84c362e985efd99288aa47defd90f334c2805c75f7ab7534b79cf8a303505f8c |