django deploy to Heroku : Server Error(500)

2024/10/5 7:23:18

I am trying to deploy my app to heroku.
Deploy was done correctly but I got Server Error(500).
When I turned DEBUG true, Sever Error doesn't occurred.
So I think there is something wrong with loading staticfiles.

I can't find any notable, critical error in log.
I have already installed whitenoise, but it doesn't work.

Is there anyone who solves this problem?

heroku logs

2019-02-26T17:01:26.064554+00:00 heroku[web.1]: State changed from down to starting
2019-02-26T17:01:34.347474+00:00 heroku[web.1]: Starting process with command `gunicorn project5.wsgi --log-file -`
2019-02-26T17:01:37.602081+00:00 heroku[web.1]: State changed from starting to up
2019-02-26T17:01:37.192553+00:00 app[web.1]: [2019-02-26 17:01:37 +0000] [4] [INFO] Starting gunicorn 19.9.0
2019-02-26T17:01:37.199091+00:00 app[web.1]: [2019-02-26 17:01:37 +0000] [4] [INFO] Listening at: http://0.0.0.0:35760 (4)
2019-02-26T17:01:37.199669+00:00 app[web.1]: [2019-02-26 17:01:37 +0000] [4] [INFO] Using worker: sync
2019-02-26T17:01:37.219788+00:00 app[web.1]: [2019-02-26 17:01:37 +0000] [10] [INFO] Booting worker with pid: 10
2019-02-26T17:01:37.317796+00:00 app[web.1]: [2019-02-26 17:01:37 +0000] [11] [INFO] Booting worker with pid: 11
2019-02-26T17:01:39.269757+00:00 heroku[router]: at=info method=GET path="/" host=shunka-blog.herokuapp.com request_id=a5a7c921-c0d2-4bc2-8831-371da12d3945 fwd="111.239.176.72" dyno=web.1 connect=0ms service=522ms status=500 bytes=234 protocol=https
2019-02-26T17:01:39.271879+00:00 app[web.1]: 10.99.220.185 - - [27/Feb/2019:02:01:39 +0900] "GET / HTTP/1.1" 500 27 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36"

settings.py

import os
import dj_database_url
import django_herokuBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))DEBUG = FalseSECRET_KEY = ***ALLOWED_HOSTS = []# Application definitionINSTALLED_APPS = ['blog5.apps.Blog5Config','django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','django.contrib.humanize','markdownx','widget_tweaks',
]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',
]STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'ROOT_URLCONF = 'project5.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 = 'project5.wsgi.application'DATABASES = { 'default': dj_database_url.config() }
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')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 = 'ja'TIME_ZONE = 'Asia/Tokyo'USE_I18N = TrueUSE_L10N = TrueUSE_TZ = TrueSTATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'# STATICFILES_DIRS = (
#     os.path.join(BASE_DIR, 'static'),
# )MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'os.makedirs(STATIC_ROOT, exist_ok=True)try:from .local_settings import *
except ImportError:passdjango_heroku.settings(locals())

wsgi.py

import os
from django.core.wsgi import get_wsgi_applicationos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project5.settings')application = get_wsgi_application()

Procfile

web: gunicorn project5.wsgi --log-file -
Answer

This doesn't have anything to do with whitenoise. The problem is your ALLOWED_HOSTS setting; this needs to have the hostname of your site.

https://en.xdnf.cn/q/70516.html

Related Q&A

Should I preallocate a numpy array?

I have a class and its method. The method repeats many times during execution. This method uses a numpy array as a temporary buffer. I dont need to store values inside the buffer between method calls. …

dup, dup2, tmpfile and stdout in python

This is a follow up question from here.Where I want do go I would like to be able to temporarily redirect the stdout into a temp file, while python still is able to print to stdout. This would involve …

How do I write a Class-Based Django Validator?

Im using Django 1.8.The documentation on writing validators has an example of a function-based validator. It also says the following on using a class:You can also use a class with a __call__() method f…

python synthesize midi with fluidsynth

I cant import fluidsynth. [Maybe theres an better module?]Im trying to synthesize midi from python or pygame. I can send midi events from pygame. Im using mingus, and it seemed pyfluidsynth would be g…

Convenient way to handle deeply nested dictionary in Python

I have a deeply nested dictionary in python thats taking up a lot of room. Is there a way to abbreviate something like this master_dictionary[sub_categories][sub_cat_name][attributes][attribute_name][s…

Running tests against existing database using pytest-django

Does anybody know how to run Django Tests using pytest-django against an existing (e.g. production) database? I know that in general, this is not what unit tests are supposed to do, but in my case, I…

Python, Timeout of Try, Except Statement after X number of seconds?

Ive been searching on this but cant seem to find an exact answer (most get into more complicated things like multithreading, etc), I just want to do something like a Try, Except statement where if the …

MemoryError while pickling data in python

I am trying to dump a dictionary into pickle format, using dump command provided in python. The file size of the dictionary is around 150 mb, but an exception occurs when only 115 mb of the file is dum…

numpy dimensions

Im a newbie to Numpy and trying to understand the basic question of what is dimension,I tried the following commands and trying to understand why the ndim for last 2 arrays are same?>>> a= ar…

DataFrame Plot: how to sort X axis

I am plotting some counts from a field of dataframe (pandas) and I found that the X axis is sorted by the counts (descending order). Instead is it possible to sort by the alphabetical order of the fiel…