I would like to filter a queryset in a view using multiple query parameters, but "request.query_params" is only able to get the first query parameter in my query string.
Here is my URLConf:
urlpatterns = [
...
re_path(r'^descsearch/$', views.DescriptionSearchView.as_view(), name='descsearch'),
]
Here is the top of my view where I'm attempting to get two query parameters from the query string ("description" and "descSearchMethod"):
class DescriptionSearchView(generics.ListAPIView):
serializer_class = DrawingSerializer
def get_queryset(self):
print("request.query_params: " + str(self.request.query_params))
description = self.request.query_params.get('description')
print("description: " + description)
descSearchMethod = self.request.query_params.get('descSearchMethod')
print("descSearchMethod: " + descSearchMethod)
...
When I make this GET request using curl:
curl -X GET http://127.0.0.1:8000/api/descsearch/?description=O-RING&descSearchMethod=and
The print statements in the Django console show that only the first query parameter "description" is in QueryDict.
request.query_params: <QueryDict: {'description': ['O-RING']}>
description: O-RING
Internal Server Error: /api/descsearch/
...
If I switch the order so that "descSearchMethod" is the first query parameter, only it shows.
Why is only the first query parameter showing in QueryDict?
self.request.GET?