gpt4 book ai didi

python - 站点地图中的优先级问题

转载 作者:太空宇宙 更新时间:2023-11-03 19:39:47 24 4
gpt4 key购买 nike

我正在尝试使用 Django 站点地图。

class BlogSiteMap(Sitemap):
"""A simple class to get sitemaps for blog"""

changefreq = 'hourly'
priority = 0.5

def items(self):
return Blog.objects.order_by('-pubDate')

def lastmod(self, obj):
return obj.pubDate

我的问题是..我想将前 3 个博客对象的优先级设置为 1.0,其余的优先级为 0.5。

我读了documentation但又没有办法摆脱它。

任何帮助将不胜感激。提前致谢。

最佳答案

我认为你可以改变每个对象的优先级。例如:

def items(self):
for i, obj in enumerate(Blog.objects.order_by('-pubDate')):
obj.priority = i < 3 and 1 or 0.5
yield obj

def priority(self, obj):
return obj.priority

关于python - 站点地图中的优先级问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/763485/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com