**
**
1.models.py Creating models
class User(models.Model):
uname= models.CharField(max_length=20)
uEmail= models.CharField(max_length=35)
uphone= models.CharField(max_length=15)
2.views.py Filter data from the database
if request.method == 'POST':
name = request.POST.get('code')
else:
name = request.GET.get('code')
UserList = User.objects.filter(uphone=name).order_by()
3. Pager
paginator = Paginator(UserList,2) # 3 posts in each page
page = request.GET.get('page')
try:
pagedata = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer deliver the first page
pagedata = paginator.page(1)
except EmptyPage:
# # If page is out of range deliver last page of results
pagedata = paginator.page(paginator.num_pages)
4. To transfer data
return (render(request,'Qt15606/students.html',{
'name':name,'page': pagedata,'pagedata': pagedata}))
5. Front end interface students.html
<div class="pagination">
<span class="step-links">
{
% if page.has_previous %}
<a href="?page=1&code={
{name}}" > first page </a>
<a class="btn btn-primary btn-lg active" href="?page={
{page.previous_page_number}}&code={
{name}}"> The previous page </a>
{
% endif %}
<span class="current">
The first {
{
page.number}} page ··· common {
{
page.paginator.num_pages}} page
</span>
{
% if page.has_next %}
<a class="btn btn-primary btn-lg active" href="?page={
{page.next_page_number }}&code={
{name}}"> The next page </a>
<a class="btn btn-primary btn-lg active" href="?page={
{page.paginator.num_pages}}&code={
{name}}"> The last page </a>
{
% endif %}
</span>
</div>
The most important step is to add filter conditions to the links .href="?page={ {page.next_page_number }}&code={ {name}}"