Django. How to debug a deployed website without turning on Debug setting

走远了吗. 提交于 2020-12-26 08:38:45

问题


I have a little forum that is already deployed and working. I just found out something is wrong with the Twitter login and I need to debug it. Right now it returns a 500 page. I can't know what is wrong with Debug = True. But if I turn it on, then I'll be violating Django security best practices, and if someone saves the info in the debug page (with Debug=False) and has bad intentions, he could cause lots of trouble. What would you recommend?


回答1:


  1. Make sure you have access to the application logs and have properly configured the AdminEmailHandler.
  2. Make sure you've property configured ALLOWED_HOSTS. If you haven't configured it and set DEBUG=False you'll see a SuspiciousOperation raised.
  3. Double check that you have the incidentals covered. Bad database connection details will quickly cause 500 errors.
  4. Have you tried running it locally with DEBUG=False? That's often a quick way to find out about some more esoteric errors.

To follow up based on the comments you'll need to turn DEBUG on in a somewhat live environment. The standard way to do this would be to have a separate staging environment from the live one. Since Heroku is being used you can easily spin up a separate environment and set DEBUG=True there. Then you'll see the full error pages, fix the error, and deploy to production where DEBUG=False.


Another idea is to setup a third-party exception handling system like Raygun or Bugsnag. Adding this to the production application will give you reports when exceptions are thrown. This is a big upgrade over Django's default email-on-error behavior.



来源:https://stackoverflow.com/questions/26868511/django-how-to-debug-a-deployed-website-without-turning-on-debug-setting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!