RSS on Turbogears 2.4

Skip to first unread message


Apr 4, 2020, 11:48:20 AM4/4/20
to TurboGears
I continue to port my project from some old version of Turbogears to 2.4.

To generate RSS feed I've used webhelpers.feedgenerator which seems outdated. Newer WebHelpers2 have not built in feed generators and recommend to use Mako templates.

So my decision was to use Kajiki engine we already have to generate feed. The issue is Kajiki refuses to process this required xml part:

<?xml version="1.0" encoding="utf-8" ?>

on top of the template file with error


kajiki.xml_template.XMLTemplateParseError: [/home/uni/projects/cafealpha-tg23/venv/cafealpha/cafealpha/templates/rssfeed.xhtml:1] XML or text declaration not at start of entity
     --> <!DOCTYPE kajiki SYSTEM "kajiki.dtd"><?xml version="1.0" encoding="utf-8" ?>
         <rss version="2.0">

Setting first tag to <!DOCTYPE xml> doesn't help.

Does anyone know right way to generate RSS or Atom feed using latest TurboGears?


Apr 10, 2020, 8:51:12 AM4/10/20
to TurboGears
Continuation of the story.

I've looked into few feed generating libraries but they either seems outdated or too large and complex for my needs.
So for now I just decided to generate very simple RSS XML manually:

    def rssfeed(self):
        feed = u'<?xml version="1.0" encoding="utf-8"?>' \
               '<rss version="2.0">'\
               '<channel>' \
               '<title>Кафе Альфа — новости</title>' \
               '<link></link>' \
               '<description>Новости команды Кафе Альфа</description><language>ru</language>'
        feed += '<lastBuildDate>{0}</lastBuildDate>'.format(
        for news in DBSession.query(News).order_by(  # last 5 news
            item = u'<item>' \
                   u'<title>{title}</title>' \
                   u'<link>{link}</link>' \
                   u'<description>{description}</description>' \
                   u'<dc:creator xmlns:dc="">{author}</dc:creator>' \
                   u'<pubDate>{date}</pubDate>' \
                   u'</item>'.format(title=news.title, link=news.url, description=news.text,
            feed += item
        feed += u'</channel></rss>'
        return feed

суббота, 4 апреля 2020 г., 18:48:20 UTC+3 пользователь Mikhail написал:
Reply all
Reply to author
0 new messages