python - Django : Can't import 'module'. Check that module AppConfig.name is correct -
might answered question, here have same problem (kind of) had. problem is, it's trick, 1 line, no explanation (and still it's different solution given works, , that's part of problem). here's project structure, simplified:
manage.py compfactu/---settings.py |--__init__.py |--core/--------__init__.py |-apps.py
so here how added app in installed_apps
:
apps.py
from django.apps import appconfig class coreconfig(appconfig): name = 'core'
settings.py
installed_apps = [ ... #compfactu modules 'compfactu.core.apps.coreconfig', ]
as read django 1.11 documentation, , quote :
new applications should avoid default_app_config. instead should require dotted path appropriate appconfig subclass configured explicitly in installed_apps.
well nice, it's new application should : i'm getting error. , it's not problem of pythonpath, cause opened python shell , can from compfactu.core.apps import coreconfig
no problem (print sys.path too, everything's fine).
but have error, here's full traceback:
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 above exception, 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 'compfactu.core.apps.coreconfig.name' correct.
and there, files , class have been generated django (manage.py startapp). , when what's told in question linked above, doing :
installed_apps = [ ... #compfactu modules 'compfactu.core', ]
it works ! , don't point ! reading doc (part i've quoted), should not work (noting don't have default_app_config
in __init__.py
.
so, question found "trick" no explanation, i'm here asking why works way when shouldn't, , why solution in official doc doesn't work?
thank in advance time.
according documentation, appconfig.name
full python path application.
appconfig.name
full python path application, e.g. 'django.contrib.admin'.
this attribute defines application configuration applies to. must set in appconfig subclasses.
it must unique across django project.
https://docs.djangoproject.com/en/1.11/ref/applications/#django.apps.appconfig.name
try this:
class coreconfig(appconfig): name = 'compfactu.core'
Comments
Post a Comment