Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue deploying django app on heroku / module not found error

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...

Some more information: enter image description here

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!

like image 364
Dim17300 Avatar asked Dec 02 '25 06:12

Dim17300


1 Answers

Well after deleting and creating another app on heroku. I generetad the staticfiles localy before pushing and it's now working just fine... :)

like image 53
Dim17300 Avatar answered Dec 03 '25 22:12

Dim17300



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!