I’m a noob, so please excuse me if this is a silly request. I am trying to create custom RSS feeds for each category of a website, but somehow I can’t manage to pass the parameter (a category slug) in order to properly build the requested feed. The RSS should be located at an address like this: http://www.website.com/category-name/feed
Here’s what I have:
In urls.py:
from project.feeds import FeedForCategory
urlpatterns = patterns('category.views',
#...
url(r'^(?P<category_slug>[a-zA-Z0-9\-]+)/feed/?$', FeedForCategory),
)
In feeds.py:
from django.contrib.syndication.feeds import Feed
class FeedForCategory(Feed):
def get_object(self, request, category_slug):
return get_object_or_404(Category, slug_name=category_slug)
def title(self, obj):
return "website.com - latest stuff"
def link(self, obj):
return "/articles/"
def description(self, obj):
return "The latest stuff from Website.com"
def get_absolute_url(self, obj):
return settings.SITE_ADDRESS + "/articles/%s/" % obj.slug_name
def items(self, obj):
return Article.objects.filter(category=category_slug)[:10]
The error that I get is: “_ init _() got an unexpected keyword argument ‘category_slug'”, but the traceback isn’t helpful, it only shows some base python stuff.
Thank you.
From the doc: https://docs.djangoproject.com/en/dev/ref/contrib/syndication/
You need to pass an instance of the feed object to your url patterns. So do this in urls.py: