Step 13: Add Rss
Okay, I coped out on Comments, and trust me, I did that for good reason. But I am not leaving you alone with everything. Lets get some RSS feeds done. Later when you have RSS you can hock it up to something like feedburner, so that you have nice stats and access to all sorts of ways to promote your site. But to do that, we first need some plain old RSS.
You could write the RSS yourself, knowing what you already know about Python and Django, as well as a little bit of xml formatting. I'm sure, if you are writing a blog, you are aware of RSS and a little of how it works. If you don't, you also will not learn to much here. Open up your main urls.py file (the one in the zing directory). Add the lines in red…
from django.conf.urls.defaults import *
from zing.blog.feed import ZingFeed
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('', (r'^admin/', include(admin.site.urls)),
(r'^', include('zing.blog.urls')),
(r'^feed/$', ZingFeed()),
)
If you were observant, you would see that we imported a file that doesn't exist, 'zing.blog.feed'. So, lets make that there file.
Go into your blog directory, and open up a new file in your text editor called 'feed.py', and add all of the following.
from django.contrib.syndication.views import Feed
from zing.blog.models import Post
class ZingFeed(Feed):
title = "My Zing Site Feed"
link = "/"
description = "Zing site, powered by Vernon's Django Recipe"
def items(self):
return Post.objects.order_by("-published")[:5]
def item_title(self, item):
return item.title
def item_description(self, item):
return item.description
def item_link(self, item):
return item.get_absolute_url()
And that is all there is to that. Open up your site in your browser, and go to whatever it is, 127.0.0.1:8000/feed/, and you should be all set. Only thing is, all the beautiful RSS that you have written is just for you, since your site isn't live on the internet yet.
So, the next step, then, is to change that.