Search code examples
pythondjangoheroku

Why am I getting an internal server error when deploying Django with Heroku (admin page still works)?


I am trying to deploy my Django website with Django with Heroku, and it keeps showing me "Internal Server Error." None of the other answers regarding this same problem here at SO solved my problem, and I noticed that I only have this problem when I set DEBUG to False.

My heroku logs commands show me the following error:

raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
ValueError: Missing staticfiles manifest entry for '/images/posting/bike.png'

I have setup my settings the following way:

ALLOWED_HOSTS = ["stratagembetaapp.herokuapp.com"]
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"
django_heroku.settings(locals())

Additionally, gunicorn, django-heroku, and whitenoise are perfectly installed. My requirements.txt and Procfile are also in order.

I have also already run the "python manage.py collectstatic" in the Heroku shell, but I still get the same result.


Solution

  • The error is that you are referencing a static file in your templates which doesn't exist (or isn't in the right place). In DEBUG mode this doesn't generate an error, but in production it does.

    Somewhere in your templates you have a reference like this:

    {% static '/images/posting/bike.png' %}
    

    I think the error here is just that leading slash, so possibly it will work if you just use {% static 'images/posting/bike.png' %}.