Django-rest-framework: Disable filtering in browsable api

Created on 21 Dec 2015  ·  3Comments  ·  Source: encode/django-rest-framework

Filtering in my browsable api leaks information of my customers, therefore I would like to disable it, like I have done with the forms in the browsable API.

Does anyone know how to do this?

Most helpful comment

Anyone looking for how to do this today, you can override the to_html method and register your custom filter backend instead of the DRF one.

``` python.py
class DisabledHTMLFilterBackend(filters.DjangoFilterBackend):

def to_html(self, request, queryset, view):
    return ""

```

See also: issue #3905

All 3 comments

I'm new to the code, could you post some example code?

Anyone looking for how to do this today, you can override the to_html method and register your custom filter backend instead of the DRF one.

``` python.py
class DisabledHTMLFilterBackend(filters.DjangoFilterBackend):

def to_html(self, request, queryset, view):
    return ""

```

See also: issue #3905

Thank you!

This is how it looks now for me (note the latter two are commented):

'DEFAULT_FILTER_BACKENDS': (
    'framework.api.filters.DisabledHTMLFilterBackend',
    'framework.api.filters.DjangoObjectPermissionsFilter',
    #'rest_framework_filters.backends.DjangoFilterBackend', # not used! 
    #'rest_framework.filters.DjangoFilterBackend',
Was this page helpful?
0 / 5 - 0 ratings

Related issues

doctorallen picture doctorallen  ·  3Comments

jpocentek picture jpocentek  ·  3Comments

synic picture synic  ·  3Comments

ryankask picture ryankask  ·  4Comments

tomchristie picture tomchristie  ·  3Comments