Django 1.2 在联合框架中带来了一些变化。据此,我现在应该能够执行以下操作:
from django.conf.urls.defaults import *
from myproject.feeds import LatestEntries, LatestEntriesByCategory
urlpatterns = patterns('',
# ...
(r'^feeds/latest/$', LatestEntries()),
(r'^feeds/categories/(?P<category_id>\d+)/$', LatestEntriesByCategory()),
)
但是当我尝试按照这些方式做任何事情时,我得到一个错误:
init () 正好需要 3 个参数(给定 1 个)
谁能给我一个工作的例子?或者也许有人明白这个错误与什么有关?
编辑#1
上面的示例实际上来自 Django Advent 链接。我尝试了很多方法,但都出现了同样的错误。但是一个简单的非工作示例是:
网址.py
urlpatterns = patterns('',
url(r'^feeds/comments/$', LatestCommentsFeed()),
)
提要.py
class LatestCommentsFeed(Feed):
description = "Latest comments left at %s" % current_site.name
feed_type = Atom1Feed
link = "/feeds/comments/"
title = "%s: Latest comments" % current_site.name
def items(self):
return Comment.objects.filter(is_public=True).order_by('-submit_date')[:50]
def item_pubdate(self,item):
return item.submit_date
def item_guid(self,item):
return "tag:%s,%s:%s" % (current_site.domain,
item.submit_date.strftime('%Y-%m-%d'),
item.get_absolute_url())