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/
I have to kind of feed: http://example.com/rss and 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
So I think I have to use CDATA into the description html tag. However, in Django (version 1.11), item_description doesn't return <description>
tag in the XML, but a <summary>
tag.
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?)
1) Self reference doesn't match document location
2) Invalid HTML: Expected '--' or 'DOCTYPE'. Not found. (5 occurrences)
I found the solution. I gave up the CDATA tag to follow this kind of structure:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.