0
我是一个noob,所以请原谅,如果这是一个愚蠢的要求。我正在尝试为网站的每个类别创建自定义RSS订阅源,但不知何故,我无法通过参数(类别段落)来正确构建请求的订阅源。 RSS的应设在这样一个地址:http://www.website.com/category-name/feed自定义Django RSS不起作用
这是我有:
在urls.py:
from project.feeds import FeedForCategory
urlpatterns = patterns('category.views',
#...
url(r'^(?P<category_slug>[a-zA-Z0-9\-]+)/feed/?$', FeedForCategory),
)
在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]
的我得到的错误是:“_ init _()得到了一个意外的关键字参数'category_slug'”,但回溯没有帮助,它只显示一些ba se python的东西。 谢谢。
好了,但如果我这样做,然后我得到: “__init __()到底需要3个参数(1给出)” – 2012-04-11 14:45:11
啊,你还使用过时的饲料类。使用'from django.contrib.syndication.views import feed' not'from django.contrib.syndication.feeds import Feed' – 2012-04-11 14:52:33
非常感谢,这对我们有很大的帮助! – 2012-04-11 15:56:52