Home > Blockchain >  Django heroku app successfully deployed but still showing an internal server error, Log files show t
Django heroku app successfully deployed but still showing an internal server error, Log files show t

Time:11-02

I am trying to deploy my Django application on Heroku but although the logs show that the build is successful and despite successful deployment the application still shows an internal server error; and this is true with debug set to either true or false. Here are the files that I think are important( also I am using the cloudinary api for this project and I am not sure if that would be the problem; anyway I still decided to include my configuration of the same herein):

My Procfile:

    web gunicorn MkusdaRegister.wsgi --log-file -

My last build log

    -----> Building on the Heroku-22 stack
    -----> Using buildpack: heroku/python
    -----> Python app detected
    -----> Using Python version specified in runtime.txt
    !     
    !     A Python security update is available! Upgrade as soon as possible to: 
    python-3.10.8
    !     See: https://devcenter.heroku.com/articles/python-runtimes
    !     
    -----> No change in requirements detected, installing from cache
    -----> Using cached install of python-3.10.7
    -----> Installing pip 22.2.2, setuptools 63.4.3 and wheel 0.37.1
    -----> Installing SQLite3
    -----> Installing requirements with pip
    -----> $ python manage.py collectstatic --noinput
    185 static files copied to '/tmp/build_f409c0b9/static'.
    -----> Discovering process types
    Procfile declares types -> web
    -----> Compressing...
    Done: 44.4M
    -----> Launching...
    Released v16
    https://mkusda-events.herokuapp.com/ deployed to Heroku
    Starting November 28th, 2022, free Heroku Dynos, free Heroku Postgres, and free 
    Heroku Data for Redis® will no longer be available.
    If you have apps using any of these resources, you must upgrade to paid plans by 
    this date to ensure your apps continue to run and to retain your data. For 
    students, we will announce a new program by the end of September. Learn more at 
    https://blog.heroku.com/next-chapter

My settings.py file:

    import os
    from pathlib import Path
    import cloudinary
    import cloudinary.uploader
    import cloudinary.api

    # Build paths inside the project like this: BASE_DIR / 'subdir'.
    BASE_DIR = Path(__file__).resolve().parent.parent


    # Quick-start development settings - unsuitable for production
    # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

    # SECURITY WARNING: keep the secret key used in production secret!

    # SECURITY WARNING: don't run with debug turned on in production!
    DEBUG = True

    ALLOWED_HOSTS = ['my-app.herokuapp.com', '127.0.0.1']


    # Application definition

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'Accounts',
        'Events',
        'cloudinary'
    ]

   MIDDLEWARE = [
       'django.middleware.security.SecurityMiddleware',
       'whitenoise.middleware.WhiteNoiseMiddleware',
       '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',
    ]

    ROOT_URLCONF = 'MkusdaRegister.urls'

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [],
            'APP_DIRS': True,
            'OPTIONS': {
                'context_processors': [
                    'django.template.context_processors.debug',
                    'django.template.context_processors.request',
                    'django.contrib.auth.context_processors.auth',
                    'django.contrib.messages.context_processors.messages',
                ],
            },
        },
    ]

    WSGI_APPLICATION = 'MkusdaRegister.wsgi.application'


    # Database
    # https://docs.djangoproject.com/en/4.1/ref/settings/#databases

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': str(os.path.join(BASE_DIR, 'db.sqlite3')),
        }
    }




    AUTH_PASSWORD_VALIDATORS = [
        {
            'NAME': 
    'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
        },
        {
            'NAME': 
    'django.contrib.auth.password_validation.CommonPasswordValidator',
        },
        {
            'NAME': 
    'django.contrib.auth.password_validation.NumericPasswordValidator',
        },
     ]



    LANGUAGE_CODE = 'en-us'

    TIME_ZONE = 'UTC'

    USE_I18N = True

    USE_TZ = True



    STATIC_ROOT = os.path.join(BASE_DIR, 'static')
    STATIC_URL = 'static/'


    cloudinary.config(
       cloud_name= "myCloudName",
       api_key = "myKey",
       api_secret = "myAPIsecret",
       secure = True
    )


    AUTH_USER_MODEL = 'Accounts.User'


    DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

My project/urls.py file:

    from django.contrib import admin
    from django.urls import path, include
    from django.conf import settings
    from django.conf.urls.static import static

    urlpatterns = [
        path('admin/', admin.site.urls),
        path('Accounts/', include('Accounts.urls')),
        path('Events/', include('Events.urls'))
    ]
    if settings.DEBUG:
        urlpatterns  = static(settings.MEDIA_URL, document_root = 
    settings.MEDIA_ROOT)

If anyone needs to see anymore of my code then just let me know; I'd really use help on this one.

CodePudding user response:

I finally figured out the issue, I had connected my heroku app to a github repository where one of my apps folder was missing some folder and files; so if by any chance you run into any problem of this kind in the future and your build is successful please try to check if you have any missing files and also remember to check your server logs, thankyou so much -Chris for suggesting that I check my logs. Happy Coding :)

CodePudding user response:

In urls.py file you have mentioned media root path but actually it's not defined in your settings.py file.

You can defined as mentioned below.

Base url to serve media files
MEDIA_URL = '/media/'
# Path where media is stored
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
  • Related