howto remove request.GET parameter

394 views
Skip to first unread message

ozgur yilmaz

unread,
Jun 2, 2011, 9:04:38 AM6/2/11
to django...@googlegroups.com
Hi,

I have a custom templatetag function like this:

@register.filter(name='rem_get_request')
def rem_get_request(getrequest,name):
req = getrequest.copy()

for get_item in name.split('&'):
if get_item in req and req[get_item]:
get_item = get_item.strip()
del req[get_item]

if req:
return u"?%s" % (req.urlencode())
return u""

"getrequest" parameter is request.GET
and "name" parameter is the parameters to be removed, splitted by '&'
(ampersand) (ie "min_price&max_price" )

The problem is:
If request.GET has more than 1 parameter (
?tag=mytag&min_price=1000&max_price=1500 ) i can remove one or more
parameters. But if request.GET contains only one parameter (
?tag=mytag ) then it doesnt work. the "if" statement works, but "del"
doesnt work. i cannot remove this last parameter. What am i doing
wrong?

Thanks for your information.

ozgur yilmaz

unread,
Jun 2, 2011, 9:58:25 AM6/2/11
to django...@googlegroups.com
I realized that, there's nothing wrong with the removing code. The
problem is the return statement. when the dictionary req is empty the
def returns u"" and somehow old request.GET remains unchanged. So i
should return a specific value, when the dictionary req is null.

2011/6/2 ozgur yilmaz <yel...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages