Django RSS Feed Issues

I am working on a blog application and am trying to create a simple RSS feed system function. However, I encounter an unusual error that does not make much sense to me. I understand what is happening, but I do not 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 got the following error (full stack trace http://dpaste.com/82510/ ):

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

This makes me think that he does not receive any items at all. However, I can go to the shell and capture those Story objects, and I can iterate over them, returning an absolute URL without any problems. Thus, it would seem that both parts of the feed work, and not just in the form of a feed. In addition, I have added some logging and I can confirm that the item function is never entered when visiting channel links. I hope I just apologize. Thanks in advance for any / any help.

+3
source share
2 answers

Go to:

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

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

Corrected. Not sure if I fully understand this ... but whatev. :)

+4
source

You identified

def get_absolute_url(self):

in the model?

also, it's nice for

if not obj:
    raise FeedDoesNotExist

to avoid errors when there is no feed result

+1
source

Source: https://habr.com/ru/post/1715485/


All Articles