希望有人可以帮助我。我使用django联合供稿网络设置了一个基本的RSS源。基本订阅源运行良好,但默认情况下,django将GUID(唯一标识符)设置为站点的链接。我希望GUID成为item.id。
我使用了以下有效的django示例:
from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse
from policebeat.models import NewsItem
class LatestEntriesFeed(Feed):
title = "Police beat site news"
link = "/sitenews/"
description = "Updates on changes and additions to police beat central."
def items(self):
return NewsItem.objects.order_by('-pub_date')[:5]
def item_title(self, item):
return item.title
def item_description(self, item):
return item.description
在django文档中,它表示如下:
# GUID -- One of the following three is optional. The framework looks
# for them in this order. This property is only used for Atom feeds
# (where it is the feed-level ID element). If not provided, the feed
# link is used as the ID.
def feed_guid(self, obj):
"""
Takes the object returned by get_object() and returns the globally
unique ID for the feed as a normal Python string.
"""
def feed_guid(self):
"""
Returns the feed's globally unique ID as a normal Python string.
但是当我在代码中添加以下内容时,我得到一个'NoneType'对象没有属性'id'错误:
def feed_guid(self, item):
return item.id
我确信我误解了这一点,但有人可以帮忙吗?
答案 0 :(得分:0)
为了其他任何试图使用item.id作为guid的人的利益。在浏览了django代码后,我找到了问题的答案。
虽然django docs声明:
def feed_guid(self, item):
return item
我实际上使用了以下工作:
def item_guid(self, item)
return item
rss Feed的GUID现在是项目的ID。