简体   繁体   中英

Enable Django DEBUG = True only for staff?

Is there any way to display the error pages the way you receive them with DEBUG = True set in the Django settings only when the user is logged in (optionally, as superuser)? IE, make Django work like DEBUG = True when the user is logged in?

Since DEBUG is a constant, I guess setting it to True for superuser requests is not going to work and would be a huge security risk aswell (you could forget to disable it again or race conditions could occur).

Is there any way to do this? How do developers debug their sites that are already in production? I saw Sentry , but that looks like several days of work to get to run hosted locally. I would appreciate a solution within django, the Django error page has always been sufficient to debug the errors that occur in my app (so far).

Setting up Django logging in a correct way is indeed an useful advice.

You can also configure Django to email site administrators when a server error occurs. In this way you can be notified in real-time when a server error occurs. In the email Django will put some useful information for debugging (very similar to those shown if DEBUG=True).

For details see the official documentation on the topic .

set up django logger:

https://docs.djangoproject.com/en/1.7/topics/logging/

it is an "industry standard" for these things, and it gives you a pretty wide set of options for logging, from severity level, to distribution method

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM