Filters values in views.py, then when you go to the next page, the filter is removed. Help me friends!
if request.method == "POST":
betForm = BetForm()
title = request.POST.get("title")
betAll = Bet.objects.filter(title__contains=title)
paginator = Paginator(betAll, 10)
page = request.GET.get('page')
try:
posts = paginator.page(page)
except PageNotAnInteger:
posts = paginator.page(1)
except EmptyPage:
posts = paginator.page(paginator.num_pages)
return render(request, 'bet/WebBet.html', {'page': page, 'posts': posts, 'home': paginator, 'form': betForm})
else:
betForm = BetForm()
betAll = Bet.objects.all()
paginator = Paginator(betAll, 10)
page = request.GET.get('page')
try:
posts = paginator.page(page)
except PageNotAnInteger:
posts = paginator.page(1)
except EmptyPage:
posts = paginator.page(paginator.num_pages)
return render(request, 'bet/WebBet.html', {'page': page, 'posts': posts, 'home': paginator, 'form': betForm})
Pagination.html
<div class="pagination">
<span class="step-links">
{% if page.has_previous %}
<a href="?page={{ page.previous_page_number }}">Previous</a>
<span class="current">
Page {{ page.number }} of {{ page.paginator.num_pages }}
</span>
{% endif %}
{% if page.has_next %}
<a href="?page={{ page.next_page_number }}">Next page</a>
{% endif %}
</span>
</div>