[英]Image missing in RSS/ATOM with Django
由於Django的文檔,我正在嘗試將圖像附加到我的ATOM和RSS聯合提要:https://docs.djangoproject.com/fr/1.11/ref/contrib/syndication/
我必須提供一種飼料: http://example.com/rss和http://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.