导入错误:没有模块名为APP_NAME(ImportError: No module named a

2019-10-19 04:08发布

我是新来的Python和我看到的SO,但不能类似的问题要弄清楚什么是错我的Django应用程序。

在settings.py我增加了我的应用程序中的虚线模块的形式:

INSTALLED_APPS = (
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'mproject.blog',
)

而回溯:

D:\py pro\mproject>python manage.py runserver 9999
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
  execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 280, in execute
    translation.activate('en-us')
  File "C:\Python27\lib\site-packages\django\utils\translation\__init__.py", line 130, in activate
    return _trans.activate(language)
  File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 188, in activate
    _active.value = translation(language)
  File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 177, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 159, in _fetch
    app = import_module(appname)
  File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 40, in import_module
    __import__(name)
ImportError: No module named blog

manage.py我有

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mproject.settings")

如何解决这个问题?

Answer 1:

我不认为你需要使用myproject.blog

只需添加blog到安装的应用程序。 那是不够的。



文章来源: ImportError: No module named app_name