python - 站点地图生成:手动更新页面的 lastmod/last_published_at
问题描述
我有PublicationsPage
一PublicationPage
堂课。PublicationsPage
显示其直接子代的列表,并将它们呈现在一个简短的预览列表中http://mysite/publications
。
class PublicationsPage(Page):
# ...
def get_context(self, request):
context = super().get_context(request)
publications = PublicationPage.objects.child_of(self).live()
context['publications'] = publications
return context
这意味着每当PublicationPage
添加/删除/修改新的列表时,列表都会相应地更新。但是由于我没有更新位置PublicationsPage
的lastmod
/last_published_at
属性,所以/publications
永远不会改变。这不会误导搜索引擎吗?
last_published_at
每次我触摸一个子条目时,一个非常糟糕的尝试可能是更新父页面的日期。
class PublicationPage(Page):
# ...
def save(self, *args, **kwargs):
result = super().save(*args, **kwargs)
from datetime import datetime
parent_page = self.get_parent()
parent_page.last_published_at = datetime.now()
parent_page.save()
return result
还有其他建议吗?
解决方案
推荐阅读
- python - Dymola 崩溃/python 应该启动程序和脚本的重启
- java - 从其他 JFrame 控制 JCheckBox
- json - Kafka 接收到的 Spark 中的 JSON 到 Dataframe 的数组
- c# - 将变量添加到十六进制流
- sqlite - SQLite rank() 通过 c# System.Data.SQLite 和 Mono.Data.Sqlite 支持分区
- r - 无法通过在函数参数中建立索引来分配列名
- python - 使用python在浏览器中捕获视频流
- odoo - 覆盖 Odoo 11 中的 javascript 函数?
- python - Mailchimp API 3.0 批量订阅 - Mailchimp3 PY
- c# - 如何通过在 C# 表单中右键单击禁用按钮来启用它?