Re: django pagination

121 views
Skip to first unread message
Message has been deleted

pa xapy

unread,
Jan 26, 2016, 8:10:06 AM1/26/16
to Django users
you want to paginate both querysets at the same page? 
i believe it's a pretty strange idea and if so, you should think how to refactor it
if you want only paginate posts, i'll recommend you to use django-pagination app of some sort, it's can be used in template

On Monday, January 25, 2016 at 5:16:31 PM UTC+3, Xristos Xristoou wrote:
i want to using Paginator in my main page for my post list. i see docs and examples for that but i thing my problem is a specific, because on my view i have two Querys not one.


def index(request):
    return render_to_response("blog/posts_list.html", {
        'categories': Category.objects.all(),
        'posts': Posts.objects.filter(publisheddate__lte=timezone.now()).order_by('-publisheddate')
    })

any idea how to use Paginator on my view ?

Xristos Xristoou

unread,
Jan 26, 2016, 8:27:58 AM1/26/16
to Django users
can you show me one examples with my view ?

pa xapy

unread,
Jan 26, 2016, 8:35:30 AM1/26/16
to Django users
if you'll decide to use some app for pagination, you can do it in template, like so https://github.com/ericflo/django-pagination/blob/master/docs/usage.txt ({% autopaginate posts 10 %})
or you can choose one of these https://www.djangopackages.com/grids/g/pagination/
there is no actual need to do it in view
but still, if you want to only paginate posts, I can't see a problem at all

Xristos Xristoou

unread,
Jan 26, 2016, 8:39:17 AM1/26/16
to Django users
if i use {autopagination} i dont need quyre on my view ?

pa xapy

unread,
Jan 26, 2016, 8:42:04 AM1/26/16
to Django users
you can read the usage doc i sent linked, but yes - you don't need to do anything with you queryset in view only pass it to template

Xristos Xristoou

unread,
Jan 26, 2016, 8:44:05 AM1/26/16
to Django users
one more question how to install this ?autopagination ?i dont see anything

pa xapy

unread,
Jan 26, 2016, 8:51:57 AM1/26/16
to Django users
are you familiar with the pip utility?
if not, i highly recommend to read about it https://pip.pypa.io/en/stable/quickstart/
if yes, you should know that you can install any application with pip install package_name
and how set it up with django - it's better if you read in instructions for package you choose

but i'm afraid that this particular app is too old and you can experience some troubles with it
anyways, you can try: pip install django-pagination

Xristos Xristoou

unread,
Jan 26, 2016, 8:59:22 AM1/26/16
to Django users
thnx you i try to use that now

Xristos Xristoou

unread,
Jan 26, 2016, 9:09:29 AM1/26/16
to Django users
i follow the simpe steps but i take error invalid syntax (pagination_tags.py, line 225)

pa xapy

unread,
Jan 26, 2016, 9:17:41 AM1/26/16
to Django users
are you using python 3?
that's actually what i talking about - it's too old
try another one, like this https://github.com/jamespacileo/django-pure-pagination - follow the instructions and i hope you'll be fine

Xristos Xristoou

unread,
Jan 26, 2016, 9:26:47 AM1/26/16
to Django users
that method is Confusing,i try to understand,i create new view or i work with current?i not understand it the using 'people' and object on they view
Message has been deleted

Xristos Xristoou

unread,
Jan 26, 2016, 1:42:38 PM1/26/16
to Django users
Reply all
Reply to author
Forward
0 new messages