jeudi 8 août 2019

Django-tables pagination per_page not working as expected

I have a django-tables2 table with pagination via the RequestConfig class.

I am trying to limit the results per page to 250 at max, to reduce database load and to keep the table organized.

This is my code to limit the per_page GET parameter.


def overview(request):

    # limit results per page to 250
    results_per_page = 25

    try:

        results_per_page = int(request.GET.get('per_page')) if request.GET.get('per_page') is not None else 25
        sanetized_results = results_per_page if results_per_page <= 250 else 250

        results_per_page = sanetized_results
    except:
        results_per_page = 25
        pass


# Create the pagination

# BREAKS HERE
    RequestConfig(request, paginate={'per_page': results_per_page }).configure(table)

The first part of the code works. however, at the RequestConfig it still uses the old per_page from the URL.

Am I missing something?




Aucun commentaire:

Enregistrer un commentaire