views:

176

answers:

2

I'm working on a blogging application, and trying to made just a simple RSS feed system function. However, I'm running into an odd bug that doesn't make a lot of sense to me. I understand what's likely going on, but I don't understand why. My RSS Feed class is below:

class RSSFeed(Feed):
    title = settings.BLOG_NAME
    description = "Recent Posts"
    def items(self):
        return Story.objects.all().order_by('-created')[:10]

    def link(self, obj):
        return obj.get_absolute_url()

However I received the following error (full stack trace at http://dpaste.com/82510/):

AttributeError: 'NoneType' object has no attribute 'startswith'

That leads me to believe that it's not receiving any objects whatsoever. However, I can drop to a shell and grab those Story objects, and I can iterate through them returning the absolute url without any problems. So it would seem both portions of the Feed work, just not when it's in feed form. Furthermore, I added some logging, and can confirm that the items function is never entered when visiting the feeds link. I'm hoping I'm just overlooking something simple. Thanks in advance for any/all help.

+1  A: 

Changing to:

class RSSFeed(Feed):
    title = settings.BLOG_NAME
    link = "/blog/"
    description = "Recent Posts"

    def items(self):
        return Story.objects.all().order_by('-created')[:10]

Fixed it. Not sure I totally understand it.. but whatev. :)

f4nt
Perhaps it expected link to take no arguments other than self, but you provided obj too
Tom Leys
A: 

have you defined

def get_absolute_url(self):

in the model?

also, it's nice to

if not obj:
    raise FeedDoesNotExist

to avoid errors when feed result is not present

zalew