0

Currently I am working on a shop management project. The project is building with django, django-rest-framework and react. I want to filter the models data. So I have installed django-filter. I need to define the url like "http://localhost:8000/api/search-products/?category=oil&product=mustard oil". How can I do this?

My product search views is-

class SearchProduct(generics.ListAPIView):
    serializer_class = ProductSerializer
    filter_backends = [filters.SearchFilter]
    search_fields = ["category", "name"]

My url is-

path("api/search-product/?<str:category>&<str:name>", SearchProduct.as_view())

Its showing page not found error.

How can I define the appropriate url path?

3
  • You don't have to define the query parameters in urls.py Commented Jul 5, 2021 at 3:07
  • Then how will it work? Commented Jul 5, 2021 at 3:57
  • Query params should not be part of the path url. They will still be covered though, and it will be handled by django-filter for you Commented Jul 5, 2021 at 5:10

1 Answer 1

1

you shouldn't define it as path parameters:

path("api/search-product/", SearchProduct.as_view())  

and you can call endpoint like this:

.../api/search-product/?search=any_thing_you_want
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.