如何使用Django(编程方式)拆分站点地图?

2024-05-18 06:53:08 发布

您现在位置:Python中文网/ 问答频道 /正文

虽然Google站点地图的限制是50k个url,但是我想把我的站点地图分成500个url。在

这是博客网站地图

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配置

^{pr2}$

以及

url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
        name='django.contrib.sitemaps.views.sitemap')

数据库模型有500多个对象,我如何分割站点地图,以便即使有5000个对象,也能被sitemap1.xml、sitemap2.xml等自动访问?在

谢谢。在

我想要一个程序化的解决方案。在

pps。不用过滤器就可以检索对象。可以使用主键(1-500),(500-1000)等。谢谢


Tags: 对象djangofromimportselfurl站点def