I'm trying to use Django Paginator in my webpage but the generated URL is wrong
Here is my code:
<div class="row">
<div class="col-auto">
<ul class="pagination">
{% if tickets.has_previous %}
<li class="page-item"><a class="page-link" href="{{current_uri}}?p=1"><<</a></li>
<li class="page-item"><a class="page-link" href="{{current_uri}}?p={{ tickets.previous_page_number }}"><</a></li>
{% else %}
<li class="page-item disabled"><a class="page-link" href=""><<</a></li>
<li class="page-item disabled"><a class="page-link" href=""><</a></li>
{% endif %}
{% for page_number in tickets.paginator.page_range|pagination_limit:tickets.number %}
{% ifequal tickets.number page_number %}
<li class="page-item active"><a class="page-link" href="{{current_uri}}?p={{page_number}}">{{page_number}}</a></li>
{% else %}
<li class="page-item"><a class="page-link" href="{{current_uri}}?p={{page_number}}">{{page_number}}</a></li>
{% endifequal %}
{% empty %}
No pages
{% endfor %}
{% if tickets.has_next %}
<li class="page-item"><a class="page-link" href="{{current_uri}}?p={{ tickets.next_page_number }}">></a></li>
<li class="page-item"><a class="page-link" href="{{current_uri}}?p={{ tickets.paginator.num_pages }}">>></a></li>
{% else %}
<li class="page-item disabled"><a class="page-link" href="">></a></li>
<li class="page-item disabled"><a class="page-link" href="">>></a></li>
{% endif %}
</ul>
</div> <!-- .col-auto -->
</div> <!-- .row -->
And this is what happened:
Let's say I visit my webpage, example.com and by default the pagination page is 1.
If I click on page 2, I'll get this url:
https://example.com/tasks/?p=2
If I click on page 3, this is the generated url:
https://example.com/tasks/?p=2?p=3
Which is wrong, and it should be:
https://example.com/tasks/?p=3
Also if I click back to page 1, I'm getting this url:
https://example.com/tasks/?p=2?p=3?p=1
I would like to know how to visit only the selected page instead of keeping the previous values.
(In short)
What I want:
https://example.com/tasks/ https://example.com/tasks/?p=2 https://example.com/tasks/?p=3 ...
What I am getting right now:
https://example.com/tasks/ https://example.com/tasks/?p=2 https://example.com/tasks/?p=2?p=3
anyone have any idea of what can be wrong?
UPDATE:
current_uri comes from this view (truncated):
return render(
request,
"project/tickets.html",
{
"tickets_count": total_count,
"tickets_filter_count": filtered_count,
"tickets": tickets,
"filter": filter_set,
"filter_project": filter_project,
"current_uri": request.get_full_path(),
},
)