I have been making a django app, and am now trying to deploy it to heroku.
However when I go on it, says Server Error (500)
, and the log says: 2017-05-27T21:00:14.634310+00:00 heroku[router]: at=info method=GET path="/" host=remberit.herokuapp.com request_id=065d27c6-9211-458f-9fc6-bb677d43581e fwd="86.13.204.65" dyno=web.1 connect=0ms service=151ms status=500 bytes=387 protocol=https
Here is my settings.py (at learst the relevant parts, but please ask if you would like the rest):
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, "staticfiles")
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
import dj_database_url
DATABASES['default'] = dj_database_url.config()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
ALLOWED_HOSTS = ['*']
DEBUG = False
try:
from .local_settings import *
except ImportError:
pass
And here is my wsgi.py:
import os
from django.core.wsgi import get_wsgi_application
#from whitenoise.django import DjangoWhiteNoise
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'remberit.settings')
django.setup()
application = get_wsgi_application()
#application = DjangoWhiteNoise(application)
Here is my Procfile:
web: gunicorn remberit.wsgi
Here is my runtime.txt:
python-3.5.2
Here is my requirements.txt:
appdirs==1.4.3
dj-database-url==0.4.2
gunicorn==19.7.1
packaging==16.8
pyparsing==2.2.0
six==1.10.0
whitenoise==3.3.0
psycopg2==2.6.2
And here is the output of pip freeze
:
appdirs==1.4.3
dj-database-url==0.4.2
gunicorn==19.7.1
packaging==16.8
pyparsing==2.2.0
six==1.10.0
whitenoise==3.3.0
Also, when I run the app locally with gunicorn remberit.wsgi
or python manage.py runserver
it works fine, it only doesn't work when I use heroku.
Please tell me if you need anymore information.
When DEBUG is False , Django will email the users listed in the ADMINS setting whenever your code raises an unhandled exception and results in an internal server error (strictly speaking, for any response with an HTTP status code of 500 or greater). This gives the administrators immediate notification of any errors.
The HTTP status code 500 is a generic error response. It means that the server encountered an unexpected condition that prevented it from fulfilling the request. This error is usually returned by the server when no other error code is suitable.
Other solution that may solve your issue: Comment out or remover the GzipManifestStaticFilesStorage from whitenoise. For some reason this is not working well.
# STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
Found this solution on Why would django fail with server 500 only when Debug=False AND db is set to production database on Heroku?
As mustapha-belkacim said, you need to migrate your apps:
heroku run python manage.py migrate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With