Django - 使用参数提供url模式

时间:2012-03-22 16:54:55

标签: python django feed

我按照文档https://docs.djangoproject.com/en/1.3/ref/contrib/syndication/#a-complex-example

中的说明构建了一个Feed

我的饲料类:

class UserRssFeed(Feed):
    def get_object(self, request, username = None, public_key = None):
        kwargs = {'username': username, 'profile__public_key': public_key}
        return get_object_or_404(User, **kwargs)

    def title(self, obj):
        return obj.username

    def link(self, obj):
        return 'http://safd/'

    def items(self, obj):
        return UserFeed.objects.filter(user = obj).get_entries()

    def item_title(self, item):
        return '[' + item.feed.name + '] ' + item.title

url.py:

from feedreader.models import UserRssFeed

urlpatterns = patterns('',
    # bla
    (r'^ownfeed/rss/(?P<username>[a-zA-Z0-9]+)/$', UserRssFeed()),
)

我收到此错误:

Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  101.                             request.path_info)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in resolve
  252.                     sub_match = pattern.resolve(new_path)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in resolve
  158.             return ResolverMatch(self.callback, args, kwargs, self.name)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in _get_callback
  169.             mod_name, func_name = get_mod_func(self._callback_str)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in get_mod_func
  113.         dot = callback.rindex('.')

Exception Type: AttributeError at /ownfeed/rss/adsf/
Exception Value: 'UserRssFeed' object has no attribute 'rindex'

Django版本是1.3.1

0 个答案:

没有答案