2014-02-05 100 views
0

我有一个django分页的问题。在我的表格中,我有13,618条记录,但是做了分页,我没有返回结果。Django限制查询

>>> from api.models import Post 
>>> posts = Post.objects.all() 
>>> posts.count() 
13618 
>>> posts = Post.objects.all()[10:10] 
>>> posts.count() 
0 
+0

你能澄清一下你的问题是什么? – suspectus

回答

5

的问题是在切片:

posts = Post.objects.all()[10:10] 

你问的第10项到第9(10-1)项目,这是一个空列表。如果你这样做同样会发生:

ls = [1,2,3] 
ls[1:1] # => [] 

它看起来像你想要的10个项目从10日开始,在这种情况下,你应该做的:

posts = Post.objects.all()[10:20] 
+0

坦克你!!!!! – lucasmg