I have this issue with pagination:
<a href="{{ request.get_full_path }}{% if request.GET %}&{% else %}?{% endif %}page={{ page_obj.previous_page_number }}">previous</a>
It works fine, but every time I click on it it adds one more ?page=1 at the end of the URL, so url looks like this after a few clicks: example/something?query_params=5&page=1&page=1&page=1&page=1
I know why that happens, it's because I hardcoded it into URL, but I have to use get_full_path because I need other query parameters together with page.
So basically I want all those query params but WITHOUT page=something being added each time I change the page. I need only one page query parameter.
You can effectively remove the page number in the view, like:
then in the view, we can work with:
we can also make a helper function for this to include the path:
and thus work with:
It is however a bit of a pity that the page object itself has no access to the request object, and that thus the pager could construct such links. I personally find this one of the shortcomings of Django's pagination system.