Make a link that maintains get params?
I've got an HTML table that lists a bunch of entries. I want to make the column headers clickable to be sorted. Problem is, I already have a bunch of filters in the URL (stuff like ?min_price=200&max_price=6000
). How can I buil开发者_StackOverflowd the link such that it keeps these params in tact? Is there a function for it? Do I have to do it in the view?
Here's a cute trick I found that might do what you want: http://andrewwilkinson.wordpress.com/2009/02/03/using-django-forms-for-get-urls/
Personally, I wouldn't do it that way. I'd use Javascript and change the DOM directly. You're not adding or removing any data if you are just sorting. If you just change the DOM you'll possibly avoid calling the server, and the user experience will be better because you won't need to reload the screen.
In your template, you can add:
your_current_url?{{ request.META.QUERY_STRING }}
to pass the current query string params on to additional links.
Hope that helps!
精彩评论