Remove value from GET dictionary and redirect to new URL
I want to have a view in my app that allows the user to remove one of many filters from the GET list, then redirect using the remaining variables in the list. How can I achieve this? Possibly having one filter-re开发者_如何转开发move view that works for all the variables the user can set in the filter.
If I understand you right you're 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 this more often you could also include this functionality in a middleware!
I think you can achieve this using jquery's 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>
精彩评论