Django: cannot import 'module'. Verify AppConfig.name module is correct

It may seem that the question has already been answered, in fact, here you have the same problem (view) that I had. My problem is that this is just a trick, one line, no explanation (and yet it is different, but the solution given works, and this part of my problem). Here is my simplified project structure:

manage.py
compfactu/---settings.py
          |--__init__.py
          |--core/--------__init__.py
                         |-apps.py  

So, here is how I added the application to INSTALLED_APPS:

apps.py

from django.apps import AppConfig


class CoreConfig(AppConfig):
    name = 'core'

settings.py

INSTALLED_APPS = [ 
    ...
    #compfactu modules
    'compfactu.core.apps.CoreConfig',
]

When I read the django 1.11 documentation, I quote:

Newer applications should avoid default_app_config. Instead, they should require that the dotted path to the corresponding AppConfig subclass be explicitly configured in INSTALLED_APPS.

, , : . pythonpath, python, from compfactu.core.apps import CoreConfig ( sys.path , ).

, :

Traceback (most recent call last):
  File "/home/jbjaillet/Projets/venvcompfactu/lib/python3.5/site-packages/django/apps/config.py", line 147, in create
    app_module = import_module(app_name)
  File "/home/jbjaillet/Projets/venvcompfactu/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'core'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jbjaillet/Projets/venvcompfactu/lib/python3.5/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/home/jbjaillet/Projets/venvcompfactu/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
    autoreload.raise_last_exception()
  File "/home/jbjaillet/Projets/venvcompfactu/lib/python3.5/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
    six.reraise(*_exception)
  File "/home/jbjaillet/Projets/venvcompfactu/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/jbjaillet/Projets/venvcompfactu/lib/python3.5/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/home/jbjaillet/Projets/venvcompfactu/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/jbjaillet/Projets/venvcompfactu/lib/python3.5/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/home/jbjaillet/Projets/venvcompfactu/lib/python3.5/site-packages/django/apps/config.py", line 151, in create
    app_name, mod_path, cls_name,
django.core.exceptions.ImproperlyConfigured: Cannot import 'core'. Check that 'compfactu.core.apps.CoreConfig.name' is correct.

django (manage.py startapp). , , , :

INSTALLED_APPS = [ 
    ...
    #compfactu modules
    'compfactu.core',
]

! ! (, ), (, default_app_config __init__.py.

, , "", , , , , ?

.

+4
1

, AppConfig.name - Python .

AppConfig.name

Python , , 'django.contrib.admin'.

, . AppConfig.

Django.

https://docs.djangoproject.com/en/2.2/ref/applications/#django.apps.AppConfig.name

:

class CoreConfig(AppConfig):
    name = 'compfactu.core'
+7

Source: https://habr.com/ru/post/1685529/


All Articles