【问题标题】:How to get first top five objects with django.views.generic.date_based.archive_index?如何使用 django.views.generic.date_based.archive_index 获得前五个对象?
【发布时间】:2011-03-23 23:00:42
【问题描述】:

我正在尝试使用这样的通用视图显示最新的 5 篇文章:

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

但是我得到了

AssertionError at /

一旦切片有,就无法过滤查询 被拍了。

我能做什么?

【问题讨论】:

    标签: python django django-queryset django-generic-views


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-06
      • 1970-01-01
      相关资源
      最近更新 更多