【发布时间】:2021-10-10 05:48:02
【问题描述】:
我需要将 lastmod 属性添加到站点地图索引。 它看起来像 django.contrib.sitemaps.views.index 虽然不包括 lastmode 这是我的 sitemap.xml:
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
<sitemap>
<loc>localhost:8000/sitemap-pages.xml</loc>
</sitemap>
</sitemapindex>
我的 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'),
站点地图.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
我该如何解决这个问题?
【问题讨论】:
标签: python django xml web sitemap