Django Atom Feeds

November 22, 2009

Django has built in support for exposing Atom feeds

Create a in the app you want to export feeds from.

from django.utils.feedgenerator import Atom1Feed
from django.contrib.sites.models import Site
from django.contrib.syndication.feeds import Feed
from import Blog

current_site = Site.objects.get_current()

class LatestEntriesFeed(Feed):
    author_name = "Title of the Feed"
    description = "Latest Entries posted to %s" %
    feed_type = Atom1Feed
    link = "/feeds/entries/"
    title = "%s : Latest Entries" %

    def items(self):
        return Blog.objects.all()[:15]

    def item_pubdate(self, pItem):
        return pItem.publication_date

    def item_guid(self, pItem):
        return "tag:%s,%s:%s" % (current_site.domain,

In the global, import that class and then refer to it from a url

from site.home.feeds import LatestEntriesFeed

feeds = {'entries' : LatestEntriesFeed}

urlpatterns += patterns('',
    (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict':feeds}),

Note that the url defined in the LatestEntriesFeed class is /feeds/entries/, and that the url spec shows /feeds/ whilst the name of the feed in the dictionary is entries.

Tags: django rss atom feed