3

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!

1

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.