Change settings.DEBUG in response to a request's source

11 views
Skip to first unread message

Silas Snider

unread,
Jun 11, 2014, 4:52:56 PM6/11/14
to django...@googlegroups.com
I'm writing an app where it'd be super helpful for logged-in users from my company to see error pages and the like as though the app was running with DEBUG=True, while still preventing ordinary users from seeing that output. I see that the docs strongly warn me against changing settings at runtime, so I was wondering how I could achieve the same effect?

Cal Leeming [Simplicity Media Ltd]

unread,
Jun 11, 2014, 6:16:02 PM6/11/14
to django...@googlegroups.com
Although I can't comment on your individual use case, it's better to enable remote error collection using something like Sentry or BugSnag. Both also support integration with other languages, such as JS, which is very handy when tracking down front end problems. There are lesser alternatives such as New Relic error collection (which ties in with their APM) and plain ol' email, but these are both considered obsolete these days. 

To answer your original question, I'd strongly advice against selectively enabling debug, but if you insist then you'd probably want to do it inside middleware. Naturally any errors that occur before the middleware is loaded won't get caught and will display the standard 500, and this could include quite a few different problems (e.g. Db connection failure). If any libraries/modules cache the settings.DEBUG property prior to the middleware being called, then this may cause some weird edge cases. Another alternative is to do is based on IP, but again this is extremely bad practice for production.

Hope this helps.

Cal


On Wednesday, June 11, 2014, Silas Snider <swsn...@gmail.com> wrote:
I'm writing an app where it'd be super helpful for logged-in users from my company to see error pages and the like as though the app was running with DEBUG=True, while still preventing ordinary users from seeing that output. I see that the docs strongly warn me against changing settings at runtime, so I was wondering how I could achieve the same effect?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7c979ac0-e8b9-4ea6-9e49-2205eeaccd90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages