I'm attempting to fix some pagination issues in a Django app. Using the Previous and Next buttons work fine, since I'm using existing variables like previous_page_number, but I'm unsure how to get the Page 1, Page 2, Page N buttons to work. Here's the Previous Page code, which works just fine:
{% if table.page and table.paginator.num_pages > 1 %}
{% block pagination %}
<nav class="pagination is-centered" role="navigation" aria-label="pagination">
{% block pagination.previous %}
{% if table.page.has_previous %}
<a href="{% querystring table.prefixed_page_field=table.page.previous_page_number %}" class="pagination-previous">Previous</a>
{% else %}
<a href="#" class="pagination-previous" disabled>Previous</a>
{% endif %}
{% endblock pagination.previous %}
And here's my current Pagination Range code, which doesn't. Specifically, the else segment is what I'm unable to get working.
{% block pagination.range %}
{% if table.page.has_previous or table.page.has_next %}
<ul class="pagination-list">
{% for p in table.page|table_page_range:table.paginator %}
{% if table.page.number == p %}
<li>
<a class="pagination-link is-current is-dark" aria-label="Page {{ table.page.number }}" aria-current="page">{{ table.page.number }}</a>
</li>
{% else %}
<li>
<a href="{% querystring table.prefixed_page_field=table.page.p %}" class="pagination-link" aria-label="Page {{ p }}">{{ p }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
{% endblock pagination.range %}
Currently, the pagination doesn't work, and the URL that gets passed ends at page= instead of page=p, whatever p is at the time. I'm uncertain how to pass p in as a readable variable, to cause it to appear in the URL. I've tried using the same format as other parts of the code not in the querystring.
{% else %}
<li>
<a href="{% querystring table.prefixed_page_field=table.page.{{ p }} %} class="pagination-link" aria-label="Page {{ p }}">{{ p }}</a>
</li>
{% endif %}
This causes an error that prevents the page loading at all, as Django can't reconcile the {{ part.