【问题标题】:Image missing in RSS/ATOM with Django使用 Django 的 RSS/ATOM 中缺少图像
【发布时间】:2020-05-06 14:00:44
【问题描述】:

感谢 Django 的文档:https://docs.djangoproject.com/fr/1.11/ref/contrib/syndication/

我必须提供一些信息:http://example.com/rsshttp://mywebsite.com/atom

rss.py

class LatestEntriesFeed(Feed):
title = "MyWebsite"
link = "/"
description = "Latest news"


def items(self):
    return Articles.objects.filter(published=True).order_by('-date')[:5]

def item_description(self, item):
    return '<![CDATA[ <img src="http://example.com/image.jpeg" /> ]]>'

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

def item_pubdate(self, item):
    return item.date

def item_updateddate(self, item):
    return item.update

def item_author_name(self, item):
    return item.author

def item_author_link(self, item):
    item_author_link = Site_URL + reverse('team', kwargs={'username': item.author})
    return item_author_link

def item_author_email(self):
    return EMAIL_HOST_USER

class LatestEntriesFeedAtom(LatestEntriesFeed):
    feed_type = Atom1Feed
    subtitle = LatestEntriesFeed.description

所以我想我必须在描述 html 标记中使用 CDATA。但是,在 Django(1.11 版)中,item_description 不会在 XML 中返回 &lt;description&gt; 标签,而是返回 &lt;summary&gt; 标签。

这很好还是问题的根源?

否则,我尝试使用 W3C 验证器进行扫描,但出现 2 个错误(或者只是警告?)

1) 自引用与文档位置不匹配

2) 无效的 HTML:应为“--”或“DOCTYPE”。未找到。 (5 次)

【问题讨论】:

    标签: python django rss atom-feed django-1.11


    【解决方案1】:

    我找到了解决方案。 我放弃了 CDATA 标签来遵循这种结构:

    def item_description(self, item):
      return '<figure><img src="http://example.com/image.jpeg" class="type:primaryImage" /><figcaption><p>My Image description</p></figcaption></figure><p>Some text</p>'
    

    Google 手册帮助了我:https://support.google.com/news/publisher-center/answer/9545420?hl=fr

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-24
      • 2017-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多