Automatically sending your Django blog posts to Twitter and Facebook

written by Herman Schaaf on June 4, 2011
Find me on Twitter, Google+ or LinkedIn

Sending your Django website posts to Twitter, Facebook, LinkedIn and a whole array of other social networks is the easiest thing imaginable.

Set up a Django Feed

Start by setting up a RSS feed with the Django syndication feed framework. There are very detailed explanations and examples there, so I won't go into that. Remember to ensure that your sites setting on the admin panel (i.o.w. in your database) is up to date and reflects the current domain you are using - Django syndication uses this to generate the URL for your posts.

Here's the code that the IronZebra website uses to aggregate its posts:

from django.contrib.syndication.views import Feed
from models import Post
from django.utils.html import strip_tags
from django.core.urlresolvers import reverse

class LatestEntriesFeed(Feed):
    title = "IronZebra.com latest posts"
    link = "/sitenews/"
    description = "Blog posts on Web Development, Django, jQuery and all things Web Startup"

    def items(self):
        return Post.objects.order_by('-date')[:5]

    def item_title(self, item):
        return item.title

    def item_description(self, item):
        return strip_tags(item.post)
        
    def item_link(self, item):
        return reverse('news.view', args=[item.id])

Hook up dlvr.it

dlvr.it is a very nice little free service with the tagline "You publish. We deliver". They follow your feeds, and automatically push it to the networks you desire. Setting it up is a snap. Just link it to the feed you set up when creating the Django RSS feed, choose the networks you want to send it to, and you're done!



If you found this post interesting, you might also like our blog post, Django: It's DRY, but you can sink your teeth into it