Django – leaving url params the same after changing page

Question:

I have link looking like that:

<a class="page-link" href="{% url 'home-paginated' page_obj.next_page_number %}">Next</a>

and function getting params from current link:

function GetParams(){
   const queryString = window.location.search;
   console.log(queryString);
   return queryString
        }

and I’d like to set href value to connection of {% url ‘home-paginated’ page_obj.next_page_number %} and value returned by GetParams function (or just window.location.search)

for example
let current link be

http://127.0.0.1:8000/2?sorted=normal

and after clicking "a" tag link should look like:

http://127.0.0.1:8000/3?sorted=normal
Asked By: KermitHQ

||

Answers:

You can encode the querystring again with {{ request.GET.urlencode }}:

<a class="page-link" href="{% url 'home-paginated' page_obj.next_page_number %}?{{ request.GET.urlencode }}">Next</a>
Answered By: Willem Van Onsem
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.