!! I have a model named blog !!
class blog(models.Model):
image = models.ImageField(upload_to='Media/awards')
title = models.CharField(max_length=255,blank=True)
content = models.TextField(blank=True)
and in the frontend I have
<div class="col-md-6" id= "mydiv">
<div>
<!-- pagination design start -->
<div class="blog_bottom_pagination">
<div class="counter">/</div>
<button class="paginate left"><i class="fas fa-angle-left"></i></button>
<button class="paginate right">
<i class="fas fa-angle-right"></i>
</button>
</div>
<!-- pagination design end -->
I don’t find any reference how i implement pagination without page refresh and render two data at a time in that div section. and paginate right and left by the button for getting next two data and will replace those previous data in that div…. thank you in advance
3
Answers
In Django, the HTML is filled with data before getting served to the end client. So if you want next page data in your front-end code and that too from Django Views then you will have to go to backend again and get the data ant that will require the page to be reloaded.
If you don’t want to reload the page then you will have to write APIs using Django Rest Framework. And in the front-end code just use those APIs to navigate between different pages.
Hope this helps!!
First of all in your
views.py
write this in your view function from which you are rendering this templateand in your html page write this most preferred boostrap pagination
So the view side should look like this:
Button to trigger ajax function on template:
Note "i" is the page number for the ajax function and "title" is the argumant for query.
Ajax function from template is at the end…
Ajax view:
The result object is now sent to the html side, now its time for the ajax function:
Hope that is what you are looking for, have fun!