I have a Django project (Python 2.7.15) with the following structure:
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
polls/
__init__.py
admin.py
apps.py
migrations/
__init__.py
models.py
tests.py
views.py
utils.py
utils/
__init__.py
filters.py
In my utils/filters.py
file I have a class MyFilter
. From polls/admin.py
, however, when I try to run from utils.filters import MyFilter
, I get ImportError: No module named filters
. How can I import my custom filter inside the polls app without renaming the polls/utils.py
module or the utils
package?
NOTE: This it's not a circular import problem. This happens even if I don't import anything from utils/filters.py
. It's a name conflict between utils/
and polls/utils.py
. Python tries to find filters.MyFilter
inside polls/utils.py
and it doesn't find it so it throws the error. I just want to figure out a way to bypass this conflict and force python to look for filters.MyFilter
inside the utils/
package in the project root.