@register.simple_tag()
def querystring_toggle(request, multi=True, page_key='page', **kwargs):
 new_querydict = request.GET.copy()
 try:
  new_querydict.pop(page_key)
 except KeyError:
  pass
 for (k, v) in kwargs.items():
  values = new_querydict.getlist(k)
  if ((k in new_querydict) and (v in values)):
   values.remove(v)
   new_querydict.setlist(k, values)
  elif (not multi):
   new_querydict[k] = v
  else:
   new_querydict.update({k: v})
 querystring = new_querydict.urlencode()
 if querystring:
  return ('?' + querystring)
 else:
  return ''

@ register . simple_tag ( ) def querystring_toggle ( request , multi = True , page_key = 'page' , ** kwargs ) : new_querydict = request . GET . copy ( ) try : new_querydict . pop ( page_key ) except KeyError : pass for ( k , v ) in kwargs . items ( ) : values = new_querydict . getlist ( k ) if ( ( k in new_querydict ) and ( v in values ) ) : values . remove ( v ) new_querydict . setlist ( k , values ) elif ( not multi ) : new_querydict [ k ] = v else : new_querydict . update ( { k : v } ) querystring = new_querydict . urlencode ( ) if querystring : return ( '?' + querystring ) else : return ''
add or remove a parameter in the http get query string .