Wednesday, September 29, 2010

Re: Django feed templates and how do I use them with images?

I did this without feed templates by putting an <img> tag inside the
description. Look at the way they did it here: http://ciclops.org/rssfeed.php
this feed w3c validates and seems to work as expected everywhere I've
tried it (feedly, Ning, firefox's display of the feed) Code is just
the ordinary from the docs:

from django.contrib.syndication.views import Feed
from django.utils import feedgenerator
from daily_image.models import Image

class LatestImagesFeed(Feed):
title = "Feed Title"
link = "www.mysite.com"
description = "Feed description"

image_template = 'feeds/image_feed.html'

def items(self):
return Image.objects.filter(pub_date__isnull=False).order_by('-
pub_date')[:10]

def item_title(self, item):
return item.title

def item_description(self, item):
desc ='<img width = "600" src = "' + 'http://
media.planetaryrings.com/' + str(item.jpg) + '"> '
desc += str(item.description) + '<p>' + str(item.credit) + '</
p>'
return desc

def item_link(self,item):
return 'http://www.mysite.com/' + str(item.pub_date)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment