Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # settings.py
- INSTALLED_APPS = [
- ...
- 'django.contrib.sitemaps',
- ...
- ]
- ...
- ROBOTS_USE_SITEMAP = True
- ROBOTS_SITEMAP_VIEW_NAME = 'main_sitemap'
- # app/urls.py
- ...
- from django.contrib.sitemaps import views as sitemap_views
- from some_app.sitemap import (
- CategoriesSitemap,
- ProductSitemap
- )
- sitemaps = {
- 'categories': CategoriesSitemap,
- 'products': ProductSitemap,
- }
- urlpatterns = [
- url(
- r'^sitemap\.xml$',
- sitemap_views.index,
- {'sitemaps': sitemaps},
- name='main_sitemap'
- ),
- url(
- r'^sitemap-(?P<section>.+)\.xml$',
- sitemap_views.sitemap,
- {'sitemaps': sitemaps},
- name='django.contrib.sitemaps.views.sitemap'
- ),
- ...
- ]
- # some_app.sitemap.py
- from django.contrib.sitemaps import Sitemap
- from .models import Product, Categories
- __all__ = (
- 'ProductSitemap',
- 'CategoriesSitemap'
- )
- class CategoriesSitemap(Sitemap):
- changefreq = "monthly"
- priority = 0.9
- protocol = "https"
- def items(self):
- return Categories.objects.exclude(depth=2)
- class ProductSitemap(Sitemap):
- changefreq = "monthly"
- priority = 0.9
- protocol = "https"
- def items(self):
- return Product.objects.filter(variants__amount__gte=1)
- def lastmod(self, obj):
- return obj.updated_at
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement