ModuleNotFoundError: No module named 'my_app’, app already in INSTALLED_APPS

ModuleNotFoundError: No module named 'my_app’, app already in INSTALLED_APPS

我正在尝试通过 Heroku 部署我的 Django 应用程序,但在 运行 具有 gunicorn wsgi 路径的生产环境之后我得到了一个 ModuleNotFound error。我的应用程序包含在 settings.py 中,并且在开发环境中运行良好。但是现在我收到部署错误。 我的项目结构有问题,因此 Procfile 与 manage.py 不在同一个目录中,我相信这可能是问题所在。非常感谢任何提示或帮助。

目录结构

 >FINALPROJECT(root)
    > .vscode
    > project5
        > brainSkills
           > migrations
           > static
           > templates
           apps.py
           models.py
           urls.py
           views.py
        > project5
           _init_.py
           settings.py
           wsgi.py
        _init_.py
        manage.py
    > venv
    .env
    .gitignore
    Procfile
    README.md
    requirements.txt

Procfile

web: gunicorn project5.project5.wsgi

wsgi.py

import os
 
from django.core.wsgi import get_wsgi_application
 
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project5.project5.settings')
 
application = get_wsgi_application()

setting.py

import os
from pathlib import Path
from dotenv import load_dotenv

INSTALLED_APPS = [
   'brainSkills',
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
]

ROOT_URLCONF = 'project5.urls'

WSGI_APPLICATION = 'project5.wsgi.application'

gunicorn project5.project5.wsgiHeroku local

后出错
5:32:28 PM web.1 |    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
5:32:28 PM web.1 |      return _bootstrap._gcd_import(name[level:], package, level)
5:32:28 PM web.1 |    File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
5:32:28 PM web.1 |    File "<frozen importlib._bootstrap>", line 991, in _find_and_load
5:32:28 PM web.1 |    File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
5:32:28 PM web.1 |  ModuleNotFoundError: No module named 'brainSkills'
5:32:28 PM web.1 |  [2020-10-12 21:32:28 +0000] [57691] [INFO] Worker exiting (pid: 57691)
5:32:28 PM web.1 |  [2020-10-12 17:32:28 -0400] [57689] [INFO] Shutting down: Master
5:32:28 PM web.1 |  [2020-10-12 17:32:28 -0400] [57689] [INFO] Reason: Worker failed to boot.
[DONE] Killing all processes with signal  SIGINT
5:32:28 PM web.1 Exited with exit code null

尝试更改将其添加到 INSTALLED_APPS 的方式:

INSTALLED_APPS = [
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'brainSkills.apps.BrainSkillsConfig',
]

有关此内容的更多信息 here。在研究这个问题时,我了解到在 Django 1.7 之前你的方法是正确的 如果 你也在你的应用程序 __init__.py 中使用了 default_app_config = 'brainSkills.apps.BrainSkillsConfig'。但是 Django 现在推荐我上面显示的方法。