Reputation: 303
I need to check an incoming URL in my view, if any parameter has been provided.
I've already checked various approaches with the request.GET option but did not find a suitable way. Most of them test for a defined parameter to be set, or none, like:
if self.request.GET.get('param'):
But what I need is the result when the URL is missing any parameter, like:
http://myapp/app/
instead of
http://myapp/app/?param=any
to set the queryset to a default.
Upvotes: 1
Views: 1206
Reputation: 3241
The documentation specifies that request.GET
is a QueryDict. Therefore, you should be able to check whether is empty by the number of keys.
if len(self.request.GET.keys()) == 0:
print("There are no parameters")
Upvotes: 1