What are you missing is that when you have filtered data from the queryset and its paginated so obviously to view the next page you need to maintain the state by passing the same filter object nome
. So the url should look something like this.
http://localhost:8000/clients/?page=2&nome=something
def get(self, request):
abc = request.GET.get['nome']) #<--- variable to get value from view
clientes = Cliente.objects.filter(
Q(nome__icontains=abc)) #<-- pass the abc variable here
formPesquisa = FormPesquisaCliente()
paginator = Paginator(clientes, 40)
page = request.GET.get('page')
clientes = paginator.get_page(page)
response = render(request, 'cliente/index.html', {
'clientes': clientes,
'formPesquisa': formPesquisa,
'abc':abc}) #<-- passing the abc variable to view to maintain the state of your filter.
response['Location'] += '?nome=' +request.GET['nome']
return response
Example Pagination Code:
<div class="pagination">
<span class="step-links">
{% if clients.has_previous %}
<a href="?page=1">« first</a>
{% if nome %}
<a href="?page={{ clientes.previous_page_number }}&nome={{ nome }}">previous</a>
{% else %}
<a href="?page={{ clientes.previous_page_number }}">previous</a>
{% endif %}
{% endif %}
<span class="current">
Page {{ clientes.number }} of {{ clientes.paginator.num_pages }}.
</span>
{% if clientes.has_next %}
{% if nome %}
<a href="?page={{ clientes.next_page_number }}&nome={{ nome }}">next</a>
<a href="?page={{ clientes.paginator.num_pages }}&nome={{ nome }}">last »</a>
{% else %}
<a href="?page={{ clientes.next_page_number }}">next</a>
<a href="?page={{ clientes.paginator.num_pages }}">last »</a>
{% endif %}
{% endif %}
</span>
</div>