[Fixed]-Heroku/Django deploy: why am I getting an error 500 with successful deploy and static collection?


You most likely have solved the problem, however this is for anyone else who has the problem in the future.

Most sites and people say that you need to update the ALLOWED_HOSTS in settings.py like so: ['www.beta800.net', ''] (or ['*'] for a quick test, NOT for production).

For me, this didn’t solve the problem, though it is important to update ALLOWED_HOSTS either way. My problem was that my app was missing the static files folders. If the logging shows you an error similar to this: UserWarning: No directory at:/app/static/ warnings.warn(u'No directory at: {}'.format(root)) this is the problem in your app as well. If that is the case, follow these steps:

  1. Locally, change the DEBUG property in settings.py to True.

  2. Make sure you have the following properties set in settings.py:

# The URL to use when referring to static files (where they will be served from)
STATIC_URL = '/static/'

# The absolute path to the directory where collectstatic will collect static files for deployment.
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

# Extra places for collectstatic to find static files.
    os.path.join(BASE_DIR, 'static'),

# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
  1. Locally, add a folder named static to the root folder.

  2. Locally, run python manage.py collectstatic. This should create another folder in your app’s root folder called staticfiles.

  3. Now you can set the DEBUG property in settings.py to False and deploy your app.


You most likely have solved this already, but for future users, you are most likely not including your staticfiles directory in your repo, and your host saas wouldn’t run that for you so you either
-commit your staticfiles to your repo; That’s not advisable.
-create a script of command to run on deployment and include creatstatic there.
-if the host service has a console like Heroku, you can just run it there.
-connect your host to your local console and check their docs for how to run py commands on your deployed environment

Leave a comment