Django heroku应用成功部署,但仍显示内部服务器错误,日志文件显示构建成功

q3qa4bjr  于 2022-11-13  发布在  Go
关注(0)|答案(2)|浏览(131)

我尝试在Heroku上部署我的Django应用程序,但是尽管日志显示构建成功,并且尽管部署成功,应用程序仍然显示内部服务器错误;这是真的调试设置为真或假。这里的文件,我认为是重要的(而且我使用的是云应用程序接口的这个项目,我不知道这是否会是问题;无论如何,我仍然决定在此包含我的相同配置):
我的过程文件:

web gunicorn MkusdaRegister.wsgi --log-file -

我的上一个生成日志

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

我的settings.py文件:

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'

我的项目/urls.py文件:

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)

如果任何人需要看到我的代码,然后只是让我知道;我真的需要你的帮助。

67up9zun

67up9zun1#

我终于解决了这个问题,我把我的heroku应用程序连接到了一个github存储库,其中一个应用程序文件夹丢失了一些文件夹和文件;因此,如果您在将来遇到任何此类问题,并且您的构建成功,请尝试检查您是否有任何丢失的文件,并记住检查您的服务器日志,非常感谢-Chris建议我检查我的日志。快乐编码:)

4zcjmb1e

4zcjmb1e2#

在urls.py文件中,您提到了介质根路径,但实际上它并没有在www.example.com文件中定义settings.py。
您可以按下面所述进行定义。

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

相关问题