Remove value from GET dictionary and redirect to new URL

I want to have a view in my application that allows the user to remove one of the many filters from the GET list, and then redirect using the remaining variables in the list. How can i achieve this? Perhaps there is one filter-delete view, which works for all variables that the user can set in the filter.

+4
source share
2 answers

If I understand correctly, you are looking for something like this:

from django.http import HttpResponseRedirect def myview(request): mypath = ..... #your redirect remove_get_variable = request.GET.pop('myvar') return HttpResponseRedirect(mypath) 

If you need it more often, you can also include this functionality in middleware!

+6
source

I think you can achieve this using the jquery library query plugin

 <script> function deleteFilterFromQuery(filter){ //remove this filter from url var newquery = $.query.Remove(filter); //redirect to the new url window.location = newquery; } </script> <a onclick="deleteFilterFromQuery(this.rel)" id="filter1RemoveLink" rel="filter1">remove filter 1 </a> <a onclick="deleteFilterFromQuery(this.rel)" id="filter1RemoveLink" rel="filter2">remove filter 2</a> <a onclick="deleteFilterFromQuery(this.rel)" id="filter1RemoveLink" rel="filter3">remove filter 3</a> 
+1
source

Source: https://habr.com/ru/post/1312066/


All Articles