import django_filters.rest_framework error

8.8k views Asked by At

I'm getting error when try to use django rest framework filters by following this tutorial. The error appear when I try to import the library:

from django_filters.rest_framework import DjangoFilterBackend

and the error message is

ImportError: No module named 'django_filters.rest_framework'

FYI I'm using these version of library:

Django==1.10.3
django-crispy-forms==1.6.1
django-filter==0.11.0
djangorestframework==3.5.3

Thank you

2

There are 2 answers

2
Sherpa On BEST ANSWER

django-filter added the rest_framework sub-package in the 0.15 release. The problem is that your environment originally had 0.11 installed.

1
Bobby On

after doing

import django_filters

use help(django_filters)

you should see

PACKAGE CONTENTS
compat
conf
constants
exceptions
fields
filters
filterset
models
rest_framework (package)
utils
views
widgets

From this point, you can tell rest_framework is a package it self, so do

from django_filters import rest_framework