简体   繁体   English

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

[英]Image missing in RSS/ATOM with Django

I'm trying to attach an image to my ATOM and RSS syndication feed thanks to the Django's documentation:https://docs.djangoproject.com/fr/1.11/ref/contrib/syndication/由于Django的文档,我正在尝试将图像附加到我的ATOM和RSS联合提要:https://docs.djangoproject.com/fr/1.11/ref/contrib/syndication/

I have to kind of feed: http://example.com/rss and http://mywebsite.com/atom我必须提供一种饲料: http://example.com/rsshttp://mywebsite.com/atom

rss.py 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

So I think I have to use CDATA into the description html tag.所以我想我必须在描述 html 标签中使用 CDATA。 However, in Django (version 1.11), item_description doesn't return <description> tag in the XML, but a <summary> tag.但是,在 Django(版本 1.11)中,item_description 不返回 XML 中的<description>标签,而是返回一个<summary>标签。

Is it fine or is it the source of the issue?它很好还是问题的根源?

Otherwise, I tried to scan with W3C validator and I get 2 errors (or just warnings?)否则,我尝试使用 W3C 验证器进行扫描,但出现 2 个错误(或只是警告?)

1) Self reference doesn't match document location 1) 自我参考与文档位置不匹配

2) Invalid HTML: Expected '--' or 'DOCTYPE'. 2) 无效的 HTML:预期为“--”或“DOCTYPE”。 Not found.未找到。 (5 occurrences) (5 次)

I found the solution.我找到了解决方案。 I gave up the CDATA tag to follow this kind of structure:我放弃了 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>'

I was helped by the Google manual: https://support.google.com/news/publisher-center/answer/9545420?hl=fr 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