0

My Django project works fine locally but as soon as I'm about to deploy to Heroku, I include this piece of code in my settings.py file:

ENV_TYPE = os.environ.get('ENV_TYPE')

if ENV_TYPE == "HEROKU":
    DEBUG = False

Now when I run python manage.py runserver locally, I get a Server Error (500) in my browser. But as soon as I change DEBUG to True, everything works fine.

What could be the issue?

Kindly note that I set DEBUG = True, but still, there's no way of viewing the error log. It shows a white screen with the Server Error (500) on top.

Toluwalemi
  • 391
  • 5
  • 16
  • Check the logs on Heroku – Robin Zigmond Jun 14 '20 at 23:17
  • @RobinZigmond I haven't deployed it yet to Heroku. The scope of the problem is within my local environment. – Toluwalemi Jun 14 '20 at 23:34
  • Then the error traceback should be on your terminal – Robin Zigmond Jun 14 '20 at 23:36
  • The only error showing on my terminal is `[15/Jun/2020 00:38:52] "GET / HTTP/1.1" 500 27` – Toluwalemi Jun 14 '20 at 23:39
  • 1
    maybe it write more info in some log file ? When Flask/Django runs on Apache/Nginx then Apache/Nginx saves some information in its log when there is Error 500. BTW: If I correctly rember when you use `DEBUG=False` then Django doesn't serve static files. If your code read some file from url which get from folder `static` then it may not work. – furas Jun 15 '20 at 01:02
  • @furas If it writes some more info in some log file, then that will be good news. However, I currently don't know how to access the log file. Also, I removed every URL from my static folder but I'm still having the same problem. – Toluwalemi Jun 15 '20 at 14:42
  • using Google "heroku logs" I found [heroku - how to see all the logs](https://stackoverflow.com/questions/2671454/heroku-how-to-see-all-the-logs) – furas Jun 15 '20 at 20:29

1 Answers1

1

I was finally able to resolve this problem after playing around my project (in a different branch).

Since I wasn't getting any error message besides the Server Error (500) in my browser, I changed the default 500 error page by adding my customised 500.html in the root of my templates folder. It was only then I was able to see the actual error with my project.

The error I saw in my terminal was ValueError: Missing staticfiles manifest entry for 'pages/img/favicon.ico'. I resolved this by using the command python manage.py collectstatic --clear. (See more details in the Django docs)

I ran the server again and everything worked fine.

Toluwalemi
  • 391
  • 5
  • 16