0

I am having hard times to append a new criteria to the existing url

say, i have this url after search-submit:

/found_items/?state=bla&score=bla

and in the result page, i have a paginator, i want that if you click on next button, the url above should remain and new ?page=number should be appended to this url.

<a href="?page={{ locs.next_page_number }}">next</a>

what is happening now is, /found_items/?state=bla&score=bla is disappearing and becoming /?page=number.

I want this: /found_items/?state=bla&score=bla&page=numer

how can i do this?

doniyor
  • 36,596
  • 57
  • 175
  • 260
  • possible duplicate of http://stackoverflow.com/questions/4293460/how-to-add-custom-parameters-to-an-url-query-string-with-python – plalx May 04 '13 at 15:36
  • and [http://stackoverflow.com/questions/2047622/how-to-paginate-django-with-other-get-variables](http://stackoverflow.com/questions/2047622/how-to-paginate-django-with-other-get-variables) – Jeff_Hd May 04 '13 at 15:42

1 Answers1

1

Doniyor,

I believe you may want to add the other parameters to the url when the page first loads, and you can set the state and score in the view so it populates those values in the rendered url. You can also set defaults for state and score in the view for when the visitor first comes to the page.

<a href="{% url 'name_of_view' %}?page={{ locs.next_page_number }}&state={{ state }}&score={{ score }}">next</a>

Or, if the GET parameters may be different for different renderings of the page, you could create the GET query string in the view and pass the whole thing to the anchor tag. (The query_parameters variable would be created by the view)

<a href="{% url 'name_of_view' %}?{{ query_parameters }}">next</a>

There are probably a few other ways to do this, but this is how I've handled similar situations.

I hope this helps, Joe

Joe J
  • 9,985
  • 16
  • 68
  • 100
  • Note, I put the url tag in there just for explicitness. This will ensure that the absolute url is inserted correctly, but I think the relative url that you have should do also. Remember that the syntax for the above url tag is for Django 1.5+ – Joe J May 04 '13 at 17:13