2015-08-03 60 views
0

虽然Google站点地图的限制是50k,但我想将我的站点地图分成500个URL。如何使用Django(以编程方式)分割站点地图?

这是博客网站地图,

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个对象,我怎么拆网站地图这样即使有5000个对象,也可以通过sitemap1.xml,sitemap2.xml等自动访问它。

谢谢。

ps。我想要一个编程解决方案。

pps。它可以检索没有过滤器的对象。可以使用主键(1-500),(500-1000)等由于

+1

我相信,如果你设置了'您的站点地图类limit'属性,则Django会自动分页您的站点地图。 – Brobin

回答

0

使用sitemap limit

from django.contrib.sitemaps import Sitemap 

class LimitSitemap(Sitemap): 
    limit = 500 

class BlogSitemap(LimitSitemap): 
    def items(self): 
     return Entry.objects.all() 
相关问题