Deploying Django To Heroku - Server Error (500)

Viewed 17564

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.

8 Answers

As mustapha-belkacim said, you need to migrate your apps:

heroku run python manage.py migrate

I also faced the same problem so the best and quickest solution is to remove this line:

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

and add this:

STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'

A 500 error could be a lot of possible things. Set DEBUG=True temporarily to get more information.

Make sure you aren't linking any non existing external file, like in my case I had few css files linked with my html but the actual files were deleted.

I experienced the same problem but when I set Debug option in the settings.py to false, the site run as expected.

Related