Adding an RSS feed

14 June 2008 10:48

Adding an RSS feed to Grokstar was something which I'd put off for a while because I thought it would be tricky. In the end, it was surprisingly simple.

The main thing which had put me off in the past was the vast number of different RSS (and Atom) formats, many of which are slightly incompatible, not to mention imprecisely specified. But core RSS 2.0 is a good simple standard, supported by pretty much all RSS feed readers, so I went with that.

All I had to do was the create a view for the blog in

import grok

from import Blog

class RSS(grok.View):

    def items(self, max=10):
        return sorted(self.context['entries'].values(),
                      key=lambda obj:obj.updated,

And create a template in rss_templates/

<?xml version="1.0"?>
<rss version="2.0" xmlns:tal="">
   <title tal:content="context/title"/>
   <link tal:content="view/application_url"/>
   <description tal:content="context/tagline"/>
   <item tal:repeat="item view/items">
     <title tal:content="item/title"/>
     <link tal:content="item/@@absolute_url"/>
     <description tal:content="item/summary"/>
     <pubDate tal:content="item/updated"/>

And I was pretty much done. The only remaining change was to add a link in the main page macro so that browsers know I have an RSS feed, like this:

<link rel="alternate"
      tal:attributes="title python:view.application().title;
                      href string:${view/application_url}/feed.rss">

Leave a comment