1

I have old project made on Django 1.11.10 and Python 2.7

Imports like below aren't working

from apps.configuration.utils import HrefModel

Traceback

 from apps.configuration.utils import HrefModel

 ImportError: No module named configuration.utils

Installed apps inside settings

 INSTALLED_APPS = [
    some django apps...

    "apps.configuration",
    "apps.nav",
    "apps.pages",

    more similar apps...
]

Project's folder structure

project_name/
├── apps
│   ├── account
│   ├── administration
│   ├── catalog
│   ├── configuration
│   │     ├── admin.py
│   │     ├── apps.py
│   │     ├── context_processors.py
│   │     ├── __init__.py
│   │     ├── lookups.py
│   │     ├── management
│   │     ├── migrations
│   │     ├── models
│   │     ├── templatetags
│   │     ├── tests.py
│   │     ├── utils
│   │     └── views.py
│   ├── content
│   ├── elastic_search
│   ├── feedback
│   ├── google_captcha
│   ├── __init__.py
│   ├── nav
│   ├── pages
│   ├── posts
│   ├── shop
├── docker-compose.yml
├── Dockerfile
├── entrypoint.sh
├── manage.py
├── requirements.txt

utils folder inside configuration app

utils/
├── bank.py
├── format.py
├── __init__.py
├── objects.py
├── pagination.py
└── slug.py

Objects.py contains the class, that I want to import

ysur67
  • 33
  • 2
  • 4
  • Is `configuration` a folder? Where is `utils.py`? You might be missing a `__init__.py` on the configuration folder. – gdef_ Apr 19 '21 at 20:43
  • `configuration` is folder, `utils.py` are placed inside it Configuration folder has `__init__.py` inside. – ysur67 Apr 19 '21 at 20:48
  • Which file contains the import statement? The import statement depends on where the "importer" file is. If you file is inside "apps", maybe this work: `from .configuration.utils import HrefModel` – wensiso Apr 19 '21 at 20:57
  • Imprter is based inside app in `apps` folder. Tried your solution, same error `from .configuration.utils import HrefModel ImportError: No module named configuration.utils` – ysur67 Apr 19 '21 at 20:59
  • Is `utils` a folder? Or do you have `utils.py`? – Code-Apprentice Apr 19 '21 at 21:10
  • Yep, utils is a folder. It has init.py inside and init has imports inside – ysur67 Apr 19 '21 at 21:13
  • There's no "app" in "apps" folder... Are you importing from `apps/configuration/apps.py`? In this case, you should use: `from .utils import HrefModel`. Also, I don't see any "HrefModel" inside the "utils" folder. Is it imported in `utils/__init__.py`? – wensiso Apr 19 '21 at 21:39
  • Oh, sorry. I meant - importer is based inside "nav" app. The importer is one of the nav's models. Yep, `HrefModel` is imported in utils' init.py – ysur67 Apr 19 '21 at 21:43

1 Answers1

0

Changed python2.7 to python3.5 and that got me rid of the exception

The Django documentation says

Python compatibility
Like Django 1.9, Django 1.10 requires Python 2.7, 3.4, or 3.5

https://docs.djangoproject.com/en/3.1/releases/1.10/

ysur67
  • 33
  • 2
  • 4