Pagination - Not Working

13 views
Skip to first unread message

Aakash Baranwal

unread,
Feb 18, 2019, 6:17:35 PM2/18/19
to django...@googlegroups.com
Hello Everyone,

I am new to Django and working towards developing a web app where 10 posts appear at a time with a "Load More" option given at last which when clicked shows the next 10 posts. I am not able to find what is going wrong with the code.

Also, it is not showing the character counter for the textbox, so kindly help me with that as well.

I am sending the screenshot of the code, pagination.py file.

Thank You in advance
1.png
5.png
4.png
2.png
3.png
6.png

Siddharth Tamang

unread,
Feb 19, 2019, 5:44:02 AM2/19/19
to django...@googlegroups.com
Are you trying pagination using JavaScript or Django?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALr9hQ02EKRB%3DUjPfgjX1Q1%2BG_QxxBovM7Xv_J9Y-Q%3DiwMLo_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
Thank you
Siddharth Tamang
AWS Certified Solutions Architect - Associate

Aakash Baranwal

unread,
Feb 19, 2019, 5:51:14 AM2/19/19
to django...@googlegroups.com
I am trying to do it using Django. I used Django Rest Framework API Guide-Pagination for reference

Aakash Baranwal

unread,
Feb 19, 2019, 5:53:57 AM2/19/19
to django...@googlegroups.com
I have also used Ajax with that. It's load more button is not working, it is showing the 10 posts which is the limit I set in the beginning, but not going beyond that.

On Tue, Feb 19, 2019 at 11:13 AM Siddharth Tamang <tamangsi...@gmail.com> wrote:

Siddharth Tamang

unread,
Feb 19, 2019, 6:11:45 AM2/19/19
to django...@googlegroups.com
Please send your views.py. You must have a home page or index page where you want to paginate records.


For more options, visit https://groups.google.com/d/optout.

Aakash Baranwal

unread,
Feb 19, 2019, 6:52:15 AM2/19/19
to django...@googlegroups.com
First image is of the Views.py which is in the API folder and second Views.py is for the project as you will notice in the images.

7.png
8.png
9.png
10.png

Godson Rapture

unread,
Feb 19, 2019, 8:09:19 AM2/19/19
to django...@googlegroups.com
Can you upload your code on github let me check where your problem is?

Aakash Baranwal

unread,
Feb 19, 2019, 8:20:55 AM2/19/19
to django...@googlegroups.com
Hello,

Thanks for offering me your help, but the problem is I can't upload it on internet as I have signed a Non Disclosure Agreement for the project in which I am working, so totally helpless in this case.

However I might be able to give a specific portion of what you might need for resolving this issue.

I am extremely sorry about this.

Siddharth Tamang

unread,
Feb 19, 2019, 8:31:32 AM2/19/19
to django...@googlegroups.com
Can you try this in your views.py?

from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator

views.py

feedTextAll = feedText.objects.order_by('-feedTexDate')
pages = Paginator(feedTextAll,5)
pageNum = request.GET.get('page')
feedtext = pages.get_page(pageNum)
return render(request, 'index.html',{'feedtext':feedtext})


and then in your html file where you want to show paginated records

{% for feedtext in feedtext%}

<!--- Display your records here--!>
      
{% endfor %}




<!--- displaying page numbers at bottom --!>

<ul class="pagination justify-content-center" style="margin:20px 0">

          {% if feedtext.has_previous %}
            <li class="page-item"><a class="page-link" href="?page=1"><<</a></li>
            <li class="page-item"><a class="page-link" href="?page={{feedtext.previous_page_number}}"><</a></li>
          {%else%}
            <li class="page-item disabled"><a class="page-link" href="#"><<</a></li>
            <li class="page-item disabled"><a class="page-link" href="#"><</a></li>
          {% endif %}
          {%for num in feedtext.paginator.page_range %}
          {% if feedtext.number == num %}
            <li class="page-item text-bold active"><a class="page-link" href="?page={{num}}">{{num}}</a></li>
          {%endif%}
          {% endfor %}
          {% if feedtext.has_next %}
            <li class="page-item"><a class="page-link" href="?page={{feedtext.next_page_number}}">></a></li>
            <li class="page-item"><a class="page-link" href="?page={{feedtext.paginator.num_pages}}">>></a></li>
          {%else%}
            <li class="page-item disabled"><a class="page-link" href="#">></a></li>
            <li class="page-item disabled"><a class="page-link" href="#">>></a></li>
          {%endif%}

      </ul>



For more options, visit https://groups.google.com/d/optout.

Godson Rapture

unread,
Feb 19, 2019, 3:31:28 PM2/19/19
to django...@googlegroups.com
Check out simple is better than complex blog. It should have a topic on pagination to help you 

Aakash Baranwal

unread,
Feb 20, 2019, 2:45:34 AM2/20/19
to django...@googlegroups.com
It did not work. I tried making it using JavaScript like in websites if you might have seen when you press the button then only it shows the content or scrolls down.


Aakash Baranwal

unread,
Feb 20, 2019, 2:46:11 AM2/20/19
to django...@googlegroups.com
Thanks a lot. I worked that out by making the Load More as a clickable button which when pressed will show the contents.

Reply all
Reply to author
Forward
0 new messages