我使用看起来像这样的类在 Django 中制作了一个 Atom 提要:
class AtomFeed(Feed):
feed_type = feedgenerator.Atom1Feed
# ...
def item_pubdate(self, post):
return datetime.datetime(post.date.year, post.date.month, post.date.day)
项目的结果 XML:
<entry>
<title>..</title>
<link href="..." rel="alternate"></link>
<updated>2010-10-18T00:00:00+02:00</updated>
<author><name>...</name></author>
<id>...</id>
<summary type="html">...</summary>
</entry>
这里要注意的是日期在 atom:updated
元素中,而不是在 atom:published
元素中。
RFC清楚地向我暗示这不是预期的用途:
The "atom:updated" element is a Date construct indicating the most recent instant in time when an entry or feed was modified in a way the publisher considers significant. Therefore, not all modifications necessarily result in a changed atom:updated value.
鉴于:
The "atom:published" element is a Date construct indicating an instant in time associated with an event early in the life cycle of the entry.
这不仅仅是一个理论问题。例如,Google Reader 似乎没有使用 updated
元素,而是使用它第一次看到该项目出现的日期。因此,它在第一次导入 Feed 时没有正确排序项目。
负责此操作的 Django 代码:
django/utils/feedgenerator.py:331
if item['pubdate'] is not None:
handler.addQuickElement(u"updated", rfc3339_date(item['pubdate']).decode('utf-8'))
似乎没有提到 published
元素。
这是 Django 中的错误吗?我误解了 Atom RFC 吗?我还缺少其他东西吗?
最佳答案
你没有遗漏任何东西。 Atom RFC 是正确的,这是 Django 中的一个已知错误;见this Django bug .
它看起来像是一个相对简单的修复程序,所以请随时进入并修补它! ^_^
关于python - 为什么 Django Atom1Feed 使用原子 :updated instead of atom:published?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4143113/