Reputation:
It seems there's no way to capture the whole query string in Django, doesn't it? I've only the solutions for capturing individual parameters.
So how can I check whether the query string exists
I want to check whether the query string itself exists (any parameters after "?"), if it does then either replace or add the parameters "param1" to it. How can I do that? For example:
localhost:8000 -> localhost:8000/?param1=a
localhost:8000/?param1=1 -> localhost:8000/?param1=bb
localhost:8000/?param1=1¶m2=fdfd -> localhost:8000/?param1=333¶m2=fdfd
localhost:8000/?param2=fdfd -> localhost:8000/?param1=1¶m2=fdfd
How can I do that?
Upvotes: 0
Views: 430
Reputation: 599788
request.GET
is is the query string, and it conforms to the dictionary interface. As with all Python containers, an empty dict is False in a boolean context. So you can check if it's empty by just doing if request.GET
.
However, in your examples it seems you're always replacing param1 anyway, do there is no need to check it first: just set the value: request.GET['param1'] = 'whatever'
.
Upvotes: 1