简体   繁体   中英

Author_name not showing up in Django syndication rss feed

I have a Django-based site. It has a feed which uses thedjango syndication framework ). Although I've specified author_name in the feed's definition, no author appears in the feed itself. An author is required to submit the feed to all the directories I've checked with.

My feeds.py looks like this:

from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Rss201rev2Feed

from Audits.models import Audit
from django.urls import reverse

class SubscriptionFeed(Feed):
    feed_type = Rss201rev2Feed
    title = "Audio feed title"
    link = "/listen/"
    description = "A description of the audio feed."

    author_name = "Example feed author"
    author_email = "example@gmail.com"

    def items(self):
        return Audits.objects.all().filter(published=True).exclude(audio_file='').order_by('-year_integer', '-month_integer')

    def item_title(self, item):
        return item.title

    def item_description(self, item):
        return item.abstract

    def item_link(self, item):
        return reverse('Podcast-Pages', args=[item.pk])

    def item_author_name(self, item):
        return "Example Item Author"

The specification for RSS2.0 on http://www.rssboard.org/rss-specification doesn't list author as required nor optional attribute of the feed -- only for items.

The source of the Rss201rev2Feed doesn't implement the feed author either, but the Atom1Feed does!

You can either use feed_type = Atom1Feed in your feed definition, or add an author attribute on your custom feed type:

class iTunesFeed(Rss201rev2Feed):
    def add_root_elements(self, handler):
        super().add_root_elements(handler)
        if self.feed['author_name'] is not None:
            handler.startElement("author", {})
            handler.addQuickElement("name", self.feed['author_name'])
            if self.feed['author_email'] is not None:
                handler.addQuickElement("email", self.feed['author_email'])
            if self.feed['author_link'] is not None:
                handler.addQuickElement("uri", self.feed['author_link'])
            handler.endElement("author")

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM