python - Dealing with URLs in Django -
So, what I'm trying to do basically, is a hockey pool app, and I have several ways Be able to filter data to see data, for example, filter by free agent, target, support, status, etc.
I plan to do this with a group of query strings, but I'm not sure what the best way would be to query these queries Pass along to say that I wanted to be on page 2 (as I'm using pagination to divide pages), depending on the goals, and only show forward, I have the following query Will be set:
? Page = 2 & Sort = G and Position = F
But if I was on that page, and it was showing me all similar information, if I click to say Instead, instead of the target of the target, I still want all my other filters in efficiency, like this:
? Page = 2 & sort = p & position = f
Since HTTP is free, I have trouble at this point about what would be the best way to do it. If someone has some good If you have thoughts, they will be greatly appreciated, thanks;)
Sean J
Most First, think about whether you actually want to save the all parameters every time or not, in the example you give, you change the sort order but the page Nkya are protected. Does it really matter, but considering that you will now have different elements on that page. Even more, if you change the filter, the currently selected page number can not even exist.
Anyway, assuming what you want, you do not have to worry about state or cookies or anything, because you already have all the necessary information in the GET parameter. You only need to change one of the parameters which is required, then re-sign the string. It's easy to do this in a template tag, because the GET parameter is stored as a query date, which is basically just a dictionary.
Something like this (unchester):
@ register.simple_tag Def url_with_changed_parameter (request, absolute, value): Parameters = Request. GET request [param] = value return "% s?% S"% (request.path, params.urlencode ())
and you will use it in your template:
{% url_with_changed_parameter request "page" 2%}
Comments
Post a Comment