# pagination in django not pagination the posts by 6 posts per page

**URL:** https://forum.djangoproject.com/t/pagination-in-django-not-pagination-the-posts-by-6-posts-per-page/11077
**Category:** Using Django
**Created:** [December 17, 2021, 11:01am UTC](https://forum.djangoproject.com/t/pagination-in-django-not-pagination-the-posts-by-6-posts-per-page/11077 "2021-12-17T11:01:27Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![desphixs](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/desphixs/32/6411_2.png) [@desphixs](https://forum.djangoproject.com/u/desphixs)
#### Post date: [December 17, 2021, 11:01am UTC](https://forum.djangoproject.com/t/pagination-in-django-not-pagination-the-posts-by-6-posts-per-page/11077/1 "2021-12-17T11:01:27Z")

</div>

after writing the view for my pagination in django, the button works fine, meaning that they load new pagesz but the problem is that all the posts still remains in all the new pages and that is not what’s expected.  
views.py

```auto
def ElementLists(request):
    vectors = Vectors.objects.filter(status="published").order_by("?")
    paginator = Paginator(vectors, 6)
    page_number = request.GET.get('page')
    vector_paginator = paginator.get_page(page_number)

```

elementlist.html

```auto
<li class="page-item">
   {% if vector_paginator.has_previous %}
      <a class="page-link" href="?page={{vector_paginator.previous_page_number}}" arialabel="Previous">
      <span class="ti-arrow-left">Previous</span>
      <span class="sr-only">Previous</span>
      </a>
   {% endif %}
</li>

<li class="page-item">
   {% if vector_paginator.has_next %}
       <a class="page-link" href="?page={{vector_paginator.next_page_number}}" aria-label="Next">
       <span class="ti-arrow-right">Load More</span>
       <span class="sr-only">Next</span>
       </a>
   {% endif %}
</li>

```

---

<div class="post-metadata">

### Author: ![CodenameTim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/codenametim/32/31507_2.png) [@CodenameTim](https://forum.djangoproject.com/u/CodenameTim)
#### Post date: [December 18, 2021, 1:40pm UTC](https://forum.djangoproject.com/t/pagination-in-django-not-pagination-the-posts-by-6-posts-per-page/11077/2 "2021-12-18T13:40:09Z")

</div>

Can you share your whole view and the part of the template that renders the elements of the collection you’re paginating?

---

<div class="post-metadata">

### Author: ![desphixs](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/desphixs/32/6411_2.png) [@desphixs](https://forum.djangoproject.com/u/desphixs)
#### Post date: [December 19, 2021, 11:35pm UTC](https://forum.djangoproject.com/t/pagination-in-django-not-pagination-the-posts-by-6-posts-per-page/11077/3 "2021-12-19T23:35:34Z")

</div>

Okay thanks for your response…This are the codes you requested

```auto
def ElementLists(request):

    vectors = Elements.objects.filter(status="published").order_by("?")

    categories = Category.objects.all()

    info = Announcements.objects.all()

    # Search Function

    query = request.GET.get("q")

    if query:

        vectors = vectors.filter(

            Q(title__icontains=query)).distinct()

   

    # Pagination Function

    paginator = Paginator(vectors, 6)

    page_number = request.GET.get('page')

    vector_paginator = paginator.get_page(page_number)

    # contexts

    context = {

        'info': info,

        'vectors': vectors,

        'categories': categories,

        'vector': vectors,

        'vector_paginator': vector_paginator,

    }

    return render(request, 'vector-lists.html', context)

```

vector-lists.html

```auto
<ul class="pagination mt-0">
    <li class="page-item">
        {% if vector_paginator.has_previous %}
        <a class="page-link" href="?page={{vector_paginator.previous_page_number}}" aria-label="Previous">
            <i class="bi bi-arrow-left-circle-fill"></i>
            <span class="sr-only">Previous</span>
        </a>
        {% endif %}
    </li>
    <!-- <li class="page-item"><a class="page-link" href="#">1</a></li> -->

    <li class="page-item">
        {% if vector_paginator.has_next %}
        <a class="page-link" href="?page={{vector_paginator.next_page_number}}" aria-label="Next">
            <i class="bi bi-arrow-right-circle-fill"></i>
            <!-- <span class="sr-only">Next</span> -->
        </a>
        {% endif %}
    </li>
</ul>

```

---

<div class="post-metadata">

### Author: ![CodenameTim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/codenametim/32/31507_2.png) [@CodenameTim](https://forum.djangoproject.com/u/CodenameTim)
#### Post date: [December 19, 2021, 11:49pm UTC](https://forum.djangoproject.com/t/pagination-in-django-not-pagination-the-posts-by-6-posts-per-page/11077/4 "2021-12-19T23:49:55Z")

</div>

You forgot the part of the template that renders the elements of the page.

---

<div class="post-metadata">

### Author: ![desphixs](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/desphixs/32/6411_2.png) [@desphixs](https://forum.djangoproject.com/u/desphixs)
#### Post date: [December 20, 2021, 5:50pm UTC](https://forum.djangoproject.com/t/pagination-in-django-not-pagination-the-posts-by-6-posts-per-page/11077/5 "2021-12-20T17:50:19Z")

</div>

okay that’s it

```auto

{% for vector in vectors %}
                    <!-- Single Image Product -->
                    <div class="col-lg-4 col-md-6 col-sm-12">
                        <div class="urip_column_three">
                            <div class="new_vid_po09i _ol3450po" style="background: linear-gradient(230deg, rgb(140, 0, 255) 0%, rgb(255, 1, 140) 100% ); "><span>{{vector.package_category}}</span></div>
                            <div class="item_image_urip">
                                <a href="{{vector.get_absolute_url}}" class="item-img">
										<img src="{{vector.image.url}}" style="height: 264px; width: 453px; object-fit: fill;" class="img-fluid" alt="" />
									</a>
                                <div class="image_urip_caption">
                                    <div class="urip_caption_flex">
                                        <div class="urip_author">
                                            <div class="urip_avater">
                                                <a href="author-detail.html.html" class="author-img">
														<img src="{{vector.creator_image.url}}" class="img-fluid" alt="" />
													</a>
                                            </div>
                                            <div class="urip_avater_place">
                                                <h3 class="urip_title"><a href="author-detail.html.html">{{vector.creator|title}}</a></h3>
                                                <span>{{vector.title|truncatechars:20}}</span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="urip_caption_last">
                                        <div class="item_list_links">
                                            <a href="premium-stock-detail.html" class="urip_link"><i class="bi bi-download"></i></a>
                                            <a href="premium-stock-detail.html" class="urip_link"><i class="bi bi-plus-circle-fill"></i></i></a>
                                            <a href="premium-stock-detail.html" class="urip_link"><i style="color: red;" class="bi bi-suit-heart-fill"></i></a>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    {% endfor %}

```

---

<div class="post-metadata">

### Author: ![CodenameTim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/codenametim/32/31507_2.png) [@CodenameTim](https://forum.djangoproject.com/u/CodenameTim)
#### Post date: [December 20, 2021, 7:41pm UTC](https://forum.djangoproject.com/t/pagination-in-django-not-pagination-the-posts-by-6-posts-per-page/11077/6 "2021-12-20T19:41:01Z")

</div>

You’re showing the elements from the `vectors` `QuerySet`. You need to be iterating over the pagination instance. Take a look at the [for loop in the template](https://docs.djangoproject.com/en/4.0/topics/pagination/) in the docs and how it differs from what you’re using.

---

<div class="post-metadata">

### Author: ![desphixs](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/desphixs/32/6411_2.png) [@desphixs](https://forum.djangoproject.com/u/desphixs)
#### Post date: [December 21, 2021, 11:03pm UTC](https://forum.djangoproject.com/t/pagination-in-django-not-pagination-the-posts-by-6-posts-per-page/11077/7 "2021-12-21T23:03:11Z")

</div>

I have tried a lot to make this work, please show me some code and that’s would be appreciated 🙏

---

<div class="post-metadata">

### Author: ![CodenameTim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/codenametim/32/31507_2.png) [@CodenameTim](https://forum.djangoproject.com/u/CodenameTim)
#### Post date: [December 21, 2021, 11:06pm UTC](https://forum.djangoproject.com/t/pagination-in-django-not-pagination-the-posts-by-6-posts-per-page/11077/8 "2021-12-21T23:06:10Z")

</div>

Rather than:

> [@desphixs](#):
>
> `{% for vector in vectors %}`

It should be:

```auto
{% for vector in vector_paginator %}

```

---

<div class="post-metadata">

### Author: ![desphixs](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/desphixs/32/6411_2.png) [@desphixs](https://forum.djangoproject.com/u/desphixs)
#### Post date: [December 23, 2021, 1:54pm UTC](https://forum.djangoproject.com/t/pagination-in-django-not-pagination-the-posts-by-6-posts-per-page/11077/9 "2021-12-23T13:54:17Z")

</div>

Thank you very much, it’s working now…You really helped me out
