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.

1 comment - leave a comment

July 25, 2010 11:49 p.m. by ddsgg

ddsgg

Leave a comment







Twitter

Jul 28 - subprocess.Popen('<what you actually want>', shell=True, stdout=subprocess.PIPE).communicate() <- so disconcerting every time...

Jul 26 - Something really ironic about how often YouTube videos freeze on Chrome

Jul 26 - @henrymyint is this true when you're observing or authoring the failure? :)