我有以下网址配置
url(r'^sitemap\.xml$', index, {'sitemaps': sitemaps}),
url(r'^sitemap-(?P<section>.+)\.xml', cache_page(86400)(sitemap), {'sitemaps': sitemaps}),
和站点地图包含以下站点地图
class ArticlesDetailSiteMap(Sitemap):
changefreq = "daily"
priority = 0.9
def items(self):
return Article.objects.filter(is_visible=True, date_published__lte=timezone.now())
但有超过50.000篇文章。所以当我尝试/sitemap-articles.xml
时,我会收到超时错误,因为它试图获取所有文章。
任何想法如何创建索引并使分页工作如下面的文档中所述,
https://docs.djangoproject.com/en/dev/ref/contrib/sitemaps/#creating-a-sitemap-index
答案 0 :(得分:3)
试试这个
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
然后
article_list = Article.objects.filter(is_visible=True, date_published__lte=timezone.now())
paginator = Paginator(article_list, 10)
page = request.GET.get('page')
try:
articles = paginator.page(page)
except PageNotAnInteger:
articles = paginator.page(1)
except EmptyPage:
articles = paginator.page(paginator.num_pages)
您可以使用sitemap\.xml?page=5
答案 1 :(得分:0)
我已将limit = 5000并解决了问题。
class ArticlesDetailSiteMap(Sitemap):
changefreq = "daily"
priority = 0.9
limit = 5000
def items(self):
return Article.objects.filter(is_visible=True, date_published__lte=timezone.now())
并为所有分页为5000的文章创建了分页网址