Django联合RSS提要中未显示author_name

时间:2018-12-24 22:34:49

标签: django rss syndication-feed

我有一个基于Django的网站。它有一个使用django syndication framework的供稿。尽管我在提要的定义中指定了author_name,但提要本身中没有作者。需要作者将提要提交到我检查过的所有目录中。

我的feeds.py看起来像这样:

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"

1 个答案:

答案 0 :(得分:1)

http://www.rssboard.org/rss-specification上的RSS2.0规范没有列出 author ,也不是供稿的可选属性-仅针对项目。

Rss201rev2Feed的源也未实现提要作者,但Atom1Feed却未实现!

您可以在Feed定义中使用feed_type = Atom1Feed,也可以在自定义Feed类型上添加author属性:

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")