Skip to main content
 首页 » 编程设计

python之Ping google 关于分页站点地图 django

2024年10月17日35JeffreyZhao

我有 15 万行的 sitemap.xml。 我正在使用分页,所以有 sitemap.xml?p=1、sitemap.xml?p=2 等

我应该如何使用 Django 将这些页面告知 Google?

或者 google 会发现 sitemap.xml 和所有带有 p 参数的页面?

谢谢。

请您参考如下方法:

Django 允许您创建 sitemap index,而不是使用带有查询参数的分页。根据文档:

You should create an index file if one of your sitemaps has more than 50,000 URLs. In this case, Django will automatically paginate the sitemap, and the index will reflect that.

在你的 URLconf 文件中你应该有类似的东西(取自 docs ):

urlpatterns = [ 
    url(r'^sitemap\.xml$', views.index, {'sitemaps': sitemaps}), 
    url(r'^sitemap-(?P<section>.+)\.xml$', views.sitemap, {'sitemaps': sitemaps}, 
        name='django.contrib.sitemaps.views.sitemap'), 
] 

请注意,section 关键字参数是必需的。

因为 sitemaps 实际上是一个代表您的站点地图类的字典(可能在 sitemap.py 中定义),Django 将创建一个站点地图索引文件 (sitemap.xml),它将引用各个站点地图文件(在您的 sitemap.py 文件中定义的站点地图 classes)。

Check here站点地图索引文件的外观。

希望这对您有所帮助!