在Django for Heroku中,当Debug = False时为什么会出现服务器(500)错误?

时间:2020-07-01 22:57:16

标签: django heroku

因此,我试图将我的本地文件提供给heroku。当我的debug = True时,一切正常,但是我现在设置debug = False,它可以正常运行,但是随后出现服务器500错误。

heroku日志-尾巴

2020-07-01T20:49:52.625458+00:00 app[web.1]: [2020-07-01 16:49:52 -0400] [10] [INFO] Worker exiting (pid: 10)
2020-07-01T20:49:52.625694+00:00 app[web.1]: [2020-07-01 16:49:52 -0400] [11] [INFO] Worker exiting (pid: 11)
2020-07-01T20:49:52.826436+00:00 app[web.1]: [2020-07-01 20:49:52 +0000] [4] [INFO] Shutting down: Master
2020-07-01T20:49:52.913999+00:00 heroku[web.1]: Process exited with status 0
2020-07-01T21:48:52.452437+00:00 heroku[web.1]: Unidling
2020-07-01T21:48:52.468183+00:00 heroku[web.1]: State changed from down to starting
2020-07-01T21:49:02.609064+00:00 heroku[web.1]: Starting process with command `gunicorn dating_project.wsgi --log-file -`
2020-07-01T21:49:04.647623+00:00 app[web.1]: [2020-07-01 21:49:04 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-07-01T21:49:04.648440+00:00 app[web.1]: [2020-07-01 21:49:04 +0000] [4] [INFO] Listening at: http://0.0.0.0:41874 (4)
2020-07-01T21:49:04.648596+00:00 app[web.1]: [2020-07-01 21:49:04 +0000] [4] [INFO] Using worker: sync
2020-07-01T21:49:04.654902+00:00 app[web.1]: [2020-07-01 21:49:04 +0000] [10] [INFO] Booting worker with pid: 10
2020-07-01T21:49:04.738652+00:00 heroku[web.1]: State changed from starting to up
2020-07-01T21:49:04.752279+00:00 app[web.1]: [2020-07-01 21:49:04 +0000] [12] [INFO] Booting worker with pid: 12
2020-07-01T21:49:06.636432+00:00 heroku[router]: at=info method=GET path="/" host=cupids-corner.herokuapp.com request_id=37718085-380c-4321-a3b2-2e5aa76f3ef9 fwd="69.171.251.32" dyno=web.1 connect=0ms service=101ms status=500 bytes=234 protocol=https
2020-07-01T21:49:06.636517+00:00 app[web.1]: 10.123.144.18 - - [01/Jul/2020:17:49:06 -0400] "GET / HTTP/1.1" 500 27 "-" "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)"
2020-07-01T22:24:34.101909+00:00 heroku[web.1]: Idling
2020-07-01T22:24:34.108226+00:00 heroku[web.1]: State changed from up to down
2020-07-01T22:24:35.649357+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-07-01T22:24:35.828680+00:00 app[web.1]: [2020-07-01 22:24:35 +0000] [4] [INFO] Handling signal: term
2020-07-01T22:24:35.833183+00:00 app[web.1]: [2020-07-01 18:24:35 -0400] [10] [INFO] Worker exiting (pid: 10)
2020-07-01T22:24:35.833979+00:00 app[web.1]: [2020-07-01 18:24:35 -0400] [12] [INFO] Worker exiting (pid: 12)
2020-07-01T22:24:36.243924+00:00 app[web.1]: [2020-07-01 22:24:36 +0000] [4] [INFO] Shutting down: Master
2020-07-01T22:24:36.503573+00:00 heroku[web.1]: Process exited with status 0
2020-07-01T22:48:24.586757+00:00 heroku[web.1]: Unidling
2020-07-01T22:48:24.598580+00:00 heroku[web.1]: State changed from down to starting
2020-07-01T22:48:34.387802+00:00 heroku[web.1]: Starting process with command `gunicorn dating_project.wsgi --log-file -`
2020-07-01T22:48:36.956090+00:00 app[web.1]: [2020-07-01 22:48:36 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-07-01T22:48:36.956686+00:00 app[web.1]: [2020-07-01 22:48:36 +0000] [4] [INFO] Listening at: http://0.0.0.0:29707 (4)
2020-07-01T22:48:36.956791+00:00 app[web.1]: [2020-07-01 22:48:36 +0000] [4] [INFO] Using worker: sync
2020-07-01T22:48:36.961548+00:00 app[web.1]: [2020-07-01 22:48:36 +0000] [10] [INFO] Booting worker with pid: 10
2020-07-01T22:48:37.011449+00:00 app[web.1]: [2020-07-01 22:48:37 +0000] [11] [INFO] Booting worker with pid: 11
2020-07-01T22:48:37.572416+00:00 heroku[web.1]: State changed from starting to up
2020-07-01T22:48:38.780576+00:00 app[web.1]: 10.35.222.75 - - [01/Jul/2020:18:48:38 -0400] "GET / HTTP/1.1" 500 27 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15"
2020-07-01T22:48:38.781637+00:00 heroku[router]: at=info method=GET path="/" host=cupids-corner.herokuapp.com request_id=9bfa7641-28d6-4c83-a614-81ca43a8f071 fwd="100.36.43.223" dyno=web.1 connect=1ms service=122ms status=500 bytes=234 protocol=https
2020-07-01T22:51:04.000000+00:00 app[api]: Build started by user rezazandirz@gmail.com
2020-07-01T22:51:47.022572+00:00 app[api]: Deploy b014ce08 by user rezazandirz@gmail.com
2020-07-01T22:51:47.022572+00:00 app[api]: Release v25 created by user rezazandirz@gmail.com
2020-07-01T22:51:47.210267+00:00 heroku[web.1]: Restarting
2020-07-01T22:51:47.224325+00:00 heroku[web.1]: State changed from up to starting
2020-07-01T22:51:48.352163+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-07-01T22:51:48.398775+00:00 app[web.1]: [2020-07-01 22:51:48 +0000] [4] [INFO] Handling signal: term
2020-07-01T22:51:48.398787+00:00 app[web.1]: [2020-07-01 18:51:48 -0400] [11] [INFO] Worker exiting (pid: 11)
2020-07-01T22:51:48.398820+00:00 app[web.1]: [2020-07-01 18:51:48 -0400] [10] [INFO] Worker exiting (pid: 10)
2020-07-01T22:51:48.598966+00:00 app[web.1]: [2020-07-01 22:51:48 +0000] [4] [INFO] Shutting down: Master
2020-07-01T22:51:48.689979+00:00 heroku[web.1]: Process exited with status 0
2020-07-01T22:51:56.987648+00:00 heroku[web.1]: Starting process with command `gunicorn dating_project.wsgi --log-file -`
2020-07-01T22:51:58.976646+00:00 app[web.1]: [2020-07-01 22:51:58 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-07-01T22:51:58.977154+00:00 app[web.1]: [2020-07-01 22:51:58 +0000] [4] [INFO] Listening at: http://0.0.0.0:11871 (4)
2020-07-01T22:51:58.977256+00:00 app[web.1]: [2020-07-01 22:51:58 +0000] [4] [INFO] Using worker: sync
2020-07-01T22:51:58.981061+00:00 app[web.1]: [2020-07-01 22:51:58 +0000] [10] [INFO] Booting worker with pid: 10
2020-07-01T22:51:59.000000+00:00 app[api]: Build succeeded
2020-07-01T22:51:59.063321+00:00 app[web.1]: [2020-07-01 22:51:59 +0000] [12] [INFO] Booting worker with pid: 12
2020-07-01T22:51:59.114928+00:00 heroku[web.1]: State changed from starting to up
2020-07-01T22:52:04.945223+00:00 app[web.1]: Internal Server Error: /
2020-07-01T22:52:04.945232+00:00 app[web.1]: Traceback (most recent call last):
2020-07-01T22:52:04.945233+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
2020-07-01T22:52:04.945234+00:00 app[web.1]: response = get_response(request)
2020-07-01T22:52:04.945234+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
2020-07-01T22:52:04.945236+00:00 app[web.1]: response = self.process_exception_by_middleware(e, request)
2020-07-01T22:52:04.945236+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
2020-07-01T22:52:04.945237+00:00 app[web.1]: response = wrapped_callback(request, *callback_args, **callback_kwargs)
2020-07-01T22:52:04.945237+00:00 app[web.1]: File "/app/dating_app/views.py", line 34, in home
2020-07-01T22:52:04.945237+00:00 app[web.1]: return render(request, 'dating_app/home.html',context)
2020-07-01T22:52:04.945238+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/shortcuts.py", line 36, in render
2020-07-01T22:52:04.945238+00:00 app[web.1]: content = loader.render_to_string(template_name, context, request, using=using)
2020-07-01T22:52:04.945239+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader.py", line 62, in render_to_string
2020-07-01T22:52:04.945239+00:00 app[web.1]: return template.render(context, request)
2020-07-01T22:52:04.945240+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py", line 61, in render
2020-07-01T22:52:04.945240+00:00 app[web.1]: return self.template.render(context)
2020-07-01T22:52:04.945240+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py", line 171, in render
2020-07-01T22:52:04.945241+00:00 app[web.1]: return self._render(context)
2020-07-01T22:52:04.945241+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py", line 163, in _render
2020-07-01T22:52:04.945241+00:00 app[web.1]: return self.nodelist.render(context)
2020-07-01T22:52:04.945242+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py", line 937, in render
2020-07-01T22:52:04.945242+00:00 app[web.1]: bit = node.render_annotated(context)
2020-07-01T22:52:04.945242+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
2020-07-01T22:52:04.945243+00:00 app[web.1]: return self.render(context)
2020-07-01T22:52:04.945243+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader_tags.py", line 150, in render
2020-07-01T22:52:04.945244+00:00 app[web.1]: return compiled_parent._render(context)
2020-07-01T22:52:04.945244+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py", line 163, in _render
2020-07-01T22:52:04.945244+00:00 app[web.1]: return self.nodelist.render(context)
2020-07-01T22:52:04.945245+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py", line 937, in render
2020-07-01T22:52:04.945245+00:00 app[web.1]: bit = node.render_annotated(context)
2020-07-01T22:52:04.945246+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
2020-07-01T22:52:04.945246+00:00 app[web.1]: return self.render(context)
2020-07-01T22:52:04.945246+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/templatetags/static.py", line 106, in render
2020-07-01T22:52:04.945267+00:00 app[web.1]: url = self.url(context)
2020-07-01T22:52:04.945268+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/templatetags/static.py", line 103, in url
2020-07-01T22:52:04.945268+00:00 app[web.1]: return self.handle_simple(path)
2020-07-01T22:52:04.945269+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/templatetags/static.py", line 118, in handle_simple
2020-07-01T22:52:04.945270+00:00 app[web.1]: return staticfiles_storage.url(path)
2020-07-01T22:52:04.945270+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 153, in url
2020-07-01T22:52:04.945270+00:00 app[web.1]: return self._url(self.stored_name, name, force)
2020-07-01T22:52:04.945271+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 132, in _url
2020-07-01T22:52:04.945271+00:00 app[web.1]: hashed_name = hashed_name_func(*args)
2020-07-01T22:52:04.945271+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 420, in stored_name
2020-07-01T22:52:04.945272+00:00 app[web.1]: raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
2020-07-01T22:52:04.945277+00:00 app[web.1]: ValueError: Missing staticfiles manifest entry for 'css/notification.css'
2020-07-01T22:52:04.946264+00:00 app[web.1]: 10.99.209.116 - - [01/Jul/2020:18:52:04 -0400] "GET / HTTP/1.1" 500 27 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15"
2020-07-01T22:52:04.946758+00:00 heroku[router]: at=info method=GET path="/" host=cupids-corner.herokuapp.com request_id=e5bb7e35-cd57-4b5b-a0cd-9940627ea7f2 fwd="100.36.43.223" dyno=web.1 connect=6ms service=128ms status=500 bytes=234 protocol=https

settings.py

    import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


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

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

ALLOWED_HOSTS = ['cupids-corner.herokuapp.com']  

LOGIN_URL = '/login/'


#For Custom Model 
AUTH_USER_MODEL = 'dating_app.Profile'


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    
    #Third party apps
    'bootstrap4', 


    #My apps
    'dating_app',
   

]

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 = 'dating_project.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 = 'dating_project.wsgi.application'


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

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


# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

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',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'US/Eastern'


USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'

PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'staticfiles')
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'dating_app/media')


#Settings for django-bootstrap3
BOOTSTRAP4 = {
    'include_jquery' : True,
}

project_root / urls.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('dating_app.urls', namespace= 'dating_app')),


] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

项目目录树,我的根文件夹和应用程序文件夹中都有一个静态副本

 .
    ├── 11_env
    │   ├── bin
    │   ├── lib
    │   └── pyvenv.cfg
    ├── Procfile
    ├── dating_app
    │   ├── __init__.py
    │   ├── __pycache__
    │   ├── admin.py
    │   ├── apps.py
    │   ├── chat.html
    │   ├── forms.py
    │   ├── media
    │   ├── migrations
    │   ├── models.py
    │   ├── static
    │   ├── tag.py
    │   ├── templates
    │   ├── templatetags
    │   ├── tests.py
    │   ├── urls.py
    │   └── views.py
    ├── dating_project
    │   ├── __init__.py
    │   ├── __pycache__
    │   ├── asgi.py
    │   ├── settings.py
    │   ├── staticfiles
    │   ├── urls.py
    │   └── wsgi.py
    ├── db.sqlite3
    ├── manage.py
    ├── requirements.txt
    └── static
        ├── css
        └── images

requirements.txt

1 个答案:

答案 0 :(得分:0)

在您的settings.py中将您的STATICFILES_STORAGE从更改为

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

我仍然不确定为什么,但这在过去对我有用!

相关问题