繁体   English   中英

带有 Django 的 RSS/ATOM 中缺少图像

[英]Image missing in RSS/ATOM with Django

由于Django的文档,我正在尝试将图像附加到我的ATOM和RSS联合提要: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 中的<description>标签,而是返回一个<summary>标签。

它很好还是问题的根源?

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

1) 自我参考与文档位置不匹配

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

我找到了解决方案。 我放弃了 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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