I need to add lastmod attribute to sitemap index. And it looks like django.contrib.sitemaps.views.index doesn't include lastmode though Here is my sitemap.xml:
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
<sitemap>
<loc>localhost:8000/sitemap-pages.xml</loc>
</sitemap>
</sitemapindex>
my urls.py
sitemaps_pages = {
'pages': sitemaps.PageViewSitemap,
'life': sitemaps.LifeViewSitemap,
'lifes': sitemaps.LifesSitemap,
'novosti': sitemaps.NewsViewSitemap,
'novost': sitemaps.NewsSitemap,
'catalog': sitemaps.CatalogViewSitemap,
'categories': sitemaps.CategorySitemap,
'regions': sitemaps.RegionSitemap,
'times': sitemaps.TimeSitemap,
'material': sitemaps.MaterialSitemap,
'products': sitemaps.ProductsSitemap,
}
path('sitemap-<section>.xml', sitemap, {'sitemaps': sitemaps_pages}, name='django.contrib.sitemaps.views.sitemap'),
path('sitemap.xml', index, {'sitemaps': sitemaps_pages}, name='django.contrib.sitemaps.views.sitemap'),
sitemaps.py
class ProductsSitemap(sitemaps.Sitemap):
protocol = 'https'
try:
priority_filter = strip_tags(Info.objects.get(name='priority_filter').value)
frequency_filter = strip_tags(Info.objects.get(name='frequency_filter').value)
except Exception:
priority_filter = '0.5'
frequency_filter = 'daily'
priority = priority_filter
changefreq = frequency_filter
limit = 1000
def items(self):
return Product.objects.all()
def location(self, item):
return str(item.url)
def lastmod(self, item):
if item.url == '/':
return Product.objects.latest('updated_at').updated_at
else:
return item.updated_at
How do i solve the problem?
Aucun commentaire:
Enregistrer un commentaire