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.

0 comments - leave a comment

Leave a comment







Twitter

Mar 10 - @drakkhen it really, really wasn't though :p

Mar 09 - Still out of power. Took a walk and about half the block seems out. Yay for the fiancee's comp which has the nice battery life. Wish tether

Mar 08 - ... and the power goes out. Wonderful. Thanks Dominion!