Hopefully someone can help me on this. I have set up a basic RSS feed using the django syndication feed network. The basic feed works well, however by default django sets the GUID (unique identifier) as a link to the site. I would like the GUID to be the item.id.
I have used the following django example which works:
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
In the django docs it states as follows:
# 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.
But when I add the following to my code I get a 'NoneType' object has no attribute 'id' error:
def feed_guid(self, item):
return item.id
I am sure I has misunderstood this but can anyone help?
For the benefit of anyone else trying to use item.id as a guid. After looking through django code itself I found the answer to my problem.
Although the django docs state:
def feed_guid(self, item):
return item
I actually used the following which worked:
def item_guid(self, item)
return item
The GUID of the rss feed is now the id of the item.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.