python - Django - Rebuild a query string without one of the variables -


i have django view processes request. want rebuild query string include variables except one.

i using list comprehension:

>>> django.http import querydict >>> q = querydict('a=2&b=4&c=test') // <--- make believe request.get >>> z = querydict('').copy() >>> z.update(dict([x x in q.items() if x[0] != 'b'])) >>> z.urlencode() 

but believe may better solution:

>>> django.http import querydict >>> q = querydict('a=2&b=4&c=test') // <--- make believe request.get >>> z = q.copy() >>> del z['b'] >>> z.urlencode() 

can think of better approach?

django puts request variables dictionary you, request.get querydict. can this:

z = request.get.copy() del z['a'] 

note dictionaries in python (and django querydicts) don't have del() method, have use python's built in del() function. querydicts immutable (but copies of them not), right copy before trying delete it. also, in last line z.urlencode() returns string, doesn't convert z url encoded string, need assign variable in order later.

hope helps


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -