Why would django fail with server 500 only when Debug=False AND db is set to production database on Heroku?

前端 未结 6 901
情歌与酒
情歌与酒 2020-12-11 18:28

When we run $ python manage.py runserver --settings=project.settings.local there are 4 different possible combinations:

  1. Debug=True && DB=l
相关标签:
6条回答
  • 2020-12-11 19:12

    The solution for me was to run python manage.py collectstatic.

    If you run $ heroku logs --tail inside terminal before doing this, the log will tell you what static files cannot be found (404).

    0 讨论(0)
  • 2020-12-11 19:14

    I have had the same issue. But then I removed this row in settings.py

    STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
    

    Now I dont have 500 error when DEBUG=False. But probably, I guess gzip functionality doesnt work anymore.

    0 讨论(0)
  • 2020-12-11 19:17

    something here helped me:

    I had a static css file link (and honestly, it had just a few lines), once I removed the link, and inserted into a tag in my main.html, it worked just fine: with DEBUG=False

    :D

    0 讨论(0)
  • 2020-12-11 19:19

    Configuring the server e-mail and seeing the stack trace as mentioned by Two-Bit Alchemist was the key. We added these lines to our settings:

    EMAIL_HOST = 'smtp.gmail.com'
    EMAIL_HOST_USER = '***'
    EMAIL_HOST_PASSWORD = '***'
    EMAIL_PORT = 587
    EMAIL_USE_TLS = True
    SERVER_EMAIL = EMAIL_HOST_USER
    

    And received an e-mail with this error in the stack trace:

    ValueError: The file 'stylesheets/application.css' could not be found with <whitenoise.django.GzipManifestStaticFilesStorage object at 0x7fdcebb94550>.
    

    We'd had problems with static files before but though we'd fixed them. The css file it's complaining about not being able to find doesn't exist anymore and isn't referenced anywhere so I'm not sure why this error is even coming up, but we fixed it by adding an empty application.css file.

    0 讨论(0)
  • 2020-12-11 19:26

    What you should be doing here is this:

    • Open up your Heroku logs by running $ heroku logs --tail in one terminal window.
    • In another terminal window run $ heroku ps:restart to restart your dynos.

    Watch the logs, and see the actual traceback. This will tell you exactly what's going on. Based on your configuration it could be a number of issues.

    0 讨论(0)
  • 2020-12-11 19:26

    I hope this helps someone someday. I had this similar problems and it took a while before i fixed it. Check your <a></a> tags. If an href attributes points to a template/link that don't exist. You might encounter such.

    0 讨论(0)
提交回复
热议问题