如何使用 Django(以编程方式)拆分站点地图?
How do I split sitemaps with Django (programatically)?
尽管 Google 站点地图限制为 50k 个网址,但我想将我的站点地图拆分为一些具有 500 个网址的站点地图。
这是博客站点地图,
from django.contrib.sitemaps import Sitemap
from blog.models import Entry
class BlogSitemap(Sitemap):
changefreq = "never"
priority = 0.5
def items(self):
return Entry.objects.all()[:500]
def lastmod(self, obj):
return obj.pub_date
URL配置
from blog.sitemaps import BlogSitemap
sitemaps = {
'blog': BlogSitemap
}
和
url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap')
数据库模型有超过 500 个对象,如何拆分站点地图以便 sitemap1.xml、sitemap2.xml 等即使有 5000 个对象也可以自动访问它?
谢谢。
ps。我想要一个程序化的解决方案。
pps。可以在没有过滤器的情况下检索对象。可以使用主键(1-500),(500-1000)等。谢谢
from django.contrib.sitemaps import Sitemap
class LimitSitemap(Sitemap):
limit = 500
class BlogSitemap(LimitSitemap):
def items(self):
return Entry.objects.all()
尽管 Google 站点地图限制为 50k 个网址,但我想将我的站点地图拆分为一些具有 500 个网址的站点地图。
这是博客站点地图,
from django.contrib.sitemaps import Sitemap
from blog.models import Entry
class BlogSitemap(Sitemap):
changefreq = "never"
priority = 0.5
def items(self):
return Entry.objects.all()[:500]
def lastmod(self, obj):
return obj.pub_date
URL配置
from blog.sitemaps import BlogSitemap
sitemaps = {
'blog': BlogSitemap
}
和
url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap')
数据库模型有超过 500 个对象,如何拆分站点地图以便 sitemap1.xml、sitemap2.xml 等即使有 5000 个对象也可以自动访问它?
谢谢。
ps。我想要一个程序化的解决方案。
pps。可以在没有过滤器的情况下检索对象。可以使用主键(1-500),(500-1000)等。谢谢
from django.contrib.sitemaps import Sitemap
class LimitSitemap(Sitemap):
limit = 500
class BlogSitemap(LimitSitemap):
def items(self):
return Entry.objects.all()