Hello! I started learning django and ran into a problem that I couldn’t solve myself myself. The following error pops up. Now python and django are globally. The same error occurred in the project through virtualenv and pyvenv on win 10. and there was no such error in Ubuntu It does the same thing. It seems like there is no module, although autocomplete is looking for this module in pycharm, it works, it does not highlight anything and everything is inserted without errors. I run the server and:

F:\web\ghc>manage.py runserver Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x03AB9300> Traceback (most recent call last): File "C:\Python35-32\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper fn(*args, **kwargs) File "C:\Python35-32\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run autoreload.raise_last_exception() File "C:\Python35-32\lib\site-packages\django\utils\autoreload.py", line 249, in raise_last_exception six.reraise(*_exception) File "C:\Python35-32\lib\site-packages\django\utils\six.py", line 685, in reraise raise value.with_traceback(tb) File "C:\Python35-32\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper fn(*args, **kwargs) File "C:\Python35-32\lib\site-packages\django\__init__.py", line 18, in setup apps.populate(settings.INSTALLED_APPS) File "C:\Python35-32\lib\site-packages\django\apps\registry.py", line 115, in populate app_config.ready() File "C:\Python35-32\lib\site-packages\django\contrib\admin\apps.py", line 22, in ready self.module.autodiscover() File "C:\Python35-32\lib\site-packages\django\contrib\admin\__init__.py", line 26, in autodiscover autodiscover_modules('admin', register_to=site) File "C:\Python35-32\lib\site-packages\django\utils\module_loading.py", line 50, in autodiscover_modules import_module('%s.%s' % (app_config.name, module_to_search)) File "C:\Python35-32\lib\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 958, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 673, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 662, in exec_module File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed File "F:\web\ghc\news\admin.py", line 3, in <module> from ghc.news.models import News ImportError: No module named 'ghc.news' Код models.py: # -*- coding: utf-8 -*- from django.db import models class News(models.Model): title = models.TextField(u'Заголовок') Код admin.py: from django.contrib import admin from ghc.news.models import News admin.site.register(News) 

Please tell me what could be the problem?

  • versions may be somewhat installed, not? - titov_andrei
  • one
    And if from news.models import News to do? - Sergey Gornostaev
  • @Sergey Gornostaev yes it happened. It’s strange that in the book and on some resources the name of the package is indicated. Apparently I used some outdated import method ... Thank you !!! now everything works. - x3zone

1 answer 1

Error in import method in new versions of django project structure changed. Import comes from the position of the manage.py file

Error from ghc.news.models import News

Right:

 from news.models import News 

But considering that you are working on 3 python which supports relative import and the call comes from the same package

Better (python 3)

 from .models import News 

No need to think what the application called, when copy-paste often saves from import errors from another application.