开发者

How to get first top five objects with django.views.generic.date_based.archive_index?

开发者 https://www.devze.com 2023-01-09 14:51 出处:网络
I\'m trying to display the latest 5 posts using a generic view like this: urlpatterns = patterns(\'\',

I'm trying to display the latest 5 posts using a generic view like this:

urlpatterns = patterns('',
  (r'^$', 'django.views.generic.date_based.archive_index', 
  {
      'queryset': Post.objects.all()[:5], 
      'date_field': 'created_on', 
      'template_name': 'index.html'}
  })

However I am getting

Asser开发者_Python百科tionError at /

Cannot filter a query once a slice has been taken.

What can I do?


num_latest: The number of latest objects to send to the template context. By default, it's 15.

0

精彩评论

暂无评论...
验证码 换一张
取 消