使用Django的RSS/ATOM中缺少图像

2024-09-30 01:32:57 发布

您现在位置:Python中文网/ 问答频道 /正文

多亏了Django的文档:https://docs.djangoproject.com/fr/1.11/ref/contrib/syndication/,我正试图将一个图像附加到ATOM和RSS联合提要上

我必须输入: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次)


Tags: django文档标记selfcomhttpreturntitle
1条回答
网友
1楼 · 发布于 2024-09-30 01:32:57

我找到了解决办法。 我放弃了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>'

我得到了谷歌手册的帮助:https://support.google.com/news/publisher-center/answer/9545420?hl=fr

相关问题 更多 >

    热门问题