An easy way to forward your django feed to feedburner

feedburner trafficIf you are using Django's syndication framework and want an easy way to track subscribers, Feedburner is probably your best bet. Of course if you already have a substantial amount of subscribers you'll want to forward the old feed to the new feed so as not to lose them.

I did this last week for this site and it worked very well, so if anyone else is trying to accomplish the same thing here is how I went about it:

First, I added the feedburner URL in settings.py (replace the URL with your own):

FEEDBURNER = 'http://feeds.feedburner.com/teebescom/'

Then, in urls.py I changed the view being called for the feed from the standard syndication view to a custom wrapper around that view.

So before it was:

url(r'^(?P(rss|atom))/$', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}),

And I changed it to:

url(r'^(?P(rss|atom))/$', 'blog.views.rss.feedburner', {'feed_dict': feeds}),

Last, I added a rss.py file in the blog.views package with the following contents:

from django.conf import settings
from django.contrib.syndication.views import feed
from django.http import HttpResponseRedirect

def feedburner(request, url, feed_dict):
    FEEDBURNER = getattr(settings, 'FEEDBURNER', None)
    if not FEEDBURNER or request.META['HTTP_USER_AGENT'].startswith('FeedBurner'):
        return feed(request, url, feed_dict)
    else:
        return HttpResponseRedirect(FEEDBURNER)

And that's it! that should be all you need.

Post a comment if you have any questions.

blog comments powered by Disqus

Twitter

Jan 25 - Registered for PyCon 2012. Woot! #fb

Jan 09 - @bsirach I identified myself to Siri as "Teebow Morel Lorset", it's what gets my name butchered the least

Jan 07 - @justincbeck @bsirach @andrewroycarter One more intern joke for Andrew! In a couple years you can have a stand-up routine for every new hire