I know that there are so many topics on this problem but I didn't find those helpful.
I am trying to push my Django app on Heroku but during the transfer, I receive a: ModuleNotFoundError : No module named 'dashboard_app.settings'
It happens when the build is trying to run the : python manage.py collecstatic
I renamed the app directory but changed everything in the settings. Everything works great on a local side, even the collectstatic
command (You can see the static files on the picture below). I have been trying to fix this all afternoon but without any success...
manage.py
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dashboard_app.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
settings.py
# Static files
if os.environ.get('PRODUCTION') == 'True':
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
# Extra places for collectstatic to find static files.
STATIC_DIRS = (
os.path.join(PROJECT_ROOT, 'static')
)
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
]
if os.environ.get('PRODUCTION') == 'True':
# Simplified static file serving
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
ROOT_URLCONF = 'dashboard_app.urls'
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dashboard_app.settings")
application = get_wsgi_application()
If someone can help me with this problem, I would appreciate a big time!