ImproperlyConfigured: apps in folder, problems when configuring application

Hi, I’ve some problem and need some help with application configuration when putting all the apps into a folder:

root@23eb465d16a0:/usr/src/invdb_v3_project_root# tree
.
├── invdb_v3_apps
│   ├── __init__py
│   ├── address
│   │   ├── __init__.py
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── migrations
│   │   ├── models.py
│   │   ├── tests.py
│   │   └── views.py
│   ├── asset
│   │   ├── __init__.py
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── forms.py
│   │   ├── migrations
│   │   ├── models.py
│   │   ├── tests.py
│   │   ├── urls.py
│   │   └── views.py
│   ├── cisco
│   │   ├── __init__.py
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── migrations
│   │   ├── models.py
│   │   ├── tests.py
│   │   └── views.py
│   ├── concierge
│   │   ├── __init__.py
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── migrations
│   │   ├── models.py
│   │   ├── tests.py
│   │   ├── urls.py
│   │   └── views.py
│   ├── customer
│   │   ├── __init__.py
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── migrations
│   │   ├── models.py
│   │   ├── tests.py
│   │   ├── urls.py
│   │   └── views.py
│   ├── misc
│   │   ├── __init__.py
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── migrations
│   │   ├── models.py
│   │   ├── tests.py
│   │   ├── urls.py
│   │   └── views.py
│   ├── peripheral
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── migrations
│   │   ├── models.py
│   │   ├── tests.py
│   │   └── views.py
│   └── service
│       ├── __init__.py
│       ├── admin.py
│       ├── apps.py
│       ├── migrations
│       │   └── __init__.py
│       ├── models.py
│       ├── tests.py
│       └── views.py
├── invdb_v3_project
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-39.pyc
│   │   ├── settings.cpython-39.pyc
│   │   ├── urls.cpython-39.pyc
│   │   └── wsgi.cpython-39.pyc
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── manage.py
├── static
│   ├── css
│   ├── images
│   └── js
├── templates
└── wait-for-service.sh

If I register the app like this:

INSTALLED_APPS = [
    'invdb_v3_apps.misc',   # is working fine
    # 'invdb_v3_apps.misc.apps.MiscConfig',
    # 'invdb_v3_apps.asset.apps.AssetConfig',
    # 'invdb_v3_apps.cisco.apps.CiscoConfig',
    # 'invdb_v3_apps.peripheral.apps.PeripheralConfig',
    # 'invdb_v3_apps.concierge.apps.ConciergeConfig',
    # 'invdb_v3_apps.address.apps.AddressConfig',
    # 'invdb_v3_apps.customer.apps.CustomerConfig',
    # 'invdb_v3_apps.service.apps.ServiceConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

But if I register the app like this:

INSTALLED_APPS = [
    # 'invdb_v3_apps.misc',
    'invdb_v3_apps.misc.apps.MiscConfig', # ends up in django.core.exceptions.ImproperlyConfigured: Cannot import 'misc'. Check that 'invdb_v3_apps.misc.apps.MiscConfig.name' is correct.
    # 'invdb_v3_apps.asset.apps.AssetConfig',
    # 'invdb_v3_apps.cisco.apps.CiscoConfig',
    # 'invdb_v3_apps.peripheral.apps.PeripheralConfig',
    # 'invdb_v3_apps.concierge.apps.ConciergeConfig',
    # 'invdb_v3_apps.address.apps.AddressConfig',
    # 'invdb_v3_apps.customer.apps.CustomerConfig',
    # 'invdb_v3_apps.service.apps.ServiceConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

I will get the following error:

invdb_v3_python_3.9.1_django | Watching for file changes with StatReloader
invdb_v3_python_3.9.1_django | Exception in thread django-main-thread:
invdb_v3_python_3.9.1_django | Traceback (most recent call last):
invdb_v3_python_3.9.1_django |   File "/usr/local/lib/python3.9/site-packages/django/apps/config.py", line 156, in create
invdb_v3_python_3.9.1_django |     app_module = import_module(app_name)
invdb_v3_python_3.9.1_django |   File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
invdb_v3_python_3.9.1_django |     return _bootstrap._gcd_import(name[level:], package, level)
invdb_v3_python_3.9.1_django |   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
invdb_v3_python_3.9.1_django |   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
invdb_v3_python_3.9.1_django |   File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
invdb_v3_python_3.9.1_django | ModuleNotFoundError: No module named 'misc'
invdb_v3_python_3.9.1_django |
invdb_v3_python_3.9.1_django | During handling of the above exception, another exception occurred:
invdb_v3_python_3.9.1_django | 
invdb_v3_python_3.9.1_django | Traceback (most recent call last):
invdb_v3_python_3.9.1_django |   File "/usr/local/lib/python3.9/threading.py", line 954, in _bootstrap_inner
invdb_v3_python_3.9.1_django |     self.run()
invdb_v3_python_3.9.1_django |   File "/usr/local/lib/python3.9/threading.py", line 892, in run
invdb_v3_python_3.9.1_django |     self._target(*self._args, **self._kwargs)
invdb_v3_python_3.9.1_django |   File "/usr/local/lib/python3.9/site-packages/django/utils/autoreload.py", line 53, in wrapper
invdb_v3_python_3.9.1_django |     fn(*args, **kwargs)
invdb_v3_python_3.9.1_django |   File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
invdb_v3_python_3.9.1_django |     autoreload.raise_last_exception()
invdb_v3_python_3.9.1_django |   File "/usr/local/lib/python3.9/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
invdb_v3_python_3.9.1_django |     raise _exception[1]
invdb_v3_python_3.9.1_django |   File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 357, in execute
invdb_v3_python_3.9.1_django |     autoreload.check_errors(django.setup)()
invdb_v3_python_3.9.1_django |   File "/usr/local/lib/python3.9/site-packages/django/utils/autoreload.py", line 53, in wrapper
invdb_v3_python_3.9.1_django |     fn(*args, **kwargs)
invdb_v3_python_3.9.1_django |   File "/usr/local/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
invdb_v3_python_3.9.1_django |     apps.populate(settings.INSTALLED_APPS)
invdb_v3_python_3.9.1_django |   File "/usr/local/lib/python3.9/site-packages/django/apps/registry.py", line 91, in populate
invdb_v3_python_3.9.1_django |     app_config = AppConfig.create(entry)
invdb_v3_python_3.9.1_django |   File "/usr/local/lib/python3.9/site-packages/django/apps/config.py", line 158, in create
invdb_v3_python_3.9.1_django |     raise ImproperlyConfigured(
invdb_v3_python_3.9.1_django | django.core.exceptions.ImproperlyConfigured: Cannot import 'misc'. Check that 'invdb_v3_apps.misc.apps.MiscConfig.name' is correct.

The app’s configuration file invdb_v3_apps/misc/apps.py looks like:

from django.apps import AppConfig


class MiscConfig(AppConfig):
    name = 'misc'
    verbose_name = 'Sonstiges'

From the docs for the AppConfig.name attribute:

Full Python path to the application, e.g. 'django.contrib.admin' .

Try setting the name attribute to ‘invdb_v3_apps.misc’.

Appreciate your response, excellent support.

I change the app configuration to:

from django.apps import AppConfig


class MiscConfig(AppConfig):
    name = 'invdb_v3_apps.misc'
    verbose_name = 'Sonstiges'

and registered the app with

INSTALLED_APPS = [
    'invdb_v3_apps.misc.apps.MiscConfig',
   ...

Now it’s working well :slight_smile: