Debugging Django with Debug set to False

116 views
Skip to first unread message

Web Architect

unread,
Jan 4, 2016, 12:33:26 PM1/4/16
to Django users
Hi,

Is there a way to debug Django when DEBUG is set to False in settings.py (for example on production)? 

The reason for asking the above is if we face any issue with DEBUG set to False and if we need to debug. 

We are new to Django and we are building an ecommerce platform based on Django. 

Would appreciate if anyone could help with the above?

Thanks.

Bill Freeman

unread,
Jan 4, 2016, 1:38:11 PM1/4/16
to django-users
You don't say what your front end is.  There are ways to use pdb with apache, look for advise on the modwsgi site.

But if you are in production, rather than just bringing up the instance that will be production, you may not want to interrupt.

Be sure that you can't reproduce the problem in the development server.  You can get debug turned off htere.

In the hard cases you need to increasing logging in the suspect code, whether by use of Django's logging or by writing to a file with explicit code.  Then you insert things in code that should have been reached, log variables, including object attributes, that are interesting, and do a binary search for the point where things differ from expectations.  (Actually, the first few logs, or even the planning of their placement, will focus your attention sufficiently to see where the code doesn't meet the design.)

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c4f16aba-f0e0-4aae-a6c0-1513571c7a97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Abraham Varricatt

unread,
Jan 5, 2016, 3:16:43 AM1/5/16
to Django users
Technically speaking, setting DEBUG=False on a production system does not render it un-debuggable. You can still debug and work with such deployments but expect resistance. An ancient approach to debugging ANY production environment is to liberally sprinkle printf (or the django log equivalent) everywhere in your code base. This has its drawbacks, but you could always push out a temporary patch to production to investigate something and revert afterwards.

Note: I do not recommend this approach. Always try to replicate issues in a development environment. Production meddling should only be a last resort and is usually an indication of a problem external to django anyways.

-Abraham V.

Remco Gerlich

unread,
Jan 5, 2016, 4:14:20 AM1/5/16
to django...@googlegroups.com
If it is the exception tracebacks you are after, consider setting up a Sentry ( https://getsentry.com/ ) server to send the error / exception logs of all your sites to. Whenever something bad happens, it'll show up there, with full tracebacks.

Greetings,
Remco Gerlich

--

Web Architect

unread,
Jan 5, 2016, 11:49:26 PM1/5/16
to Django users
Thanks all for the responses and I would certainly consider them for production level debugging. I understand that application level debugging could be achieved by various logging mechanisms or tools.

But one of my main concern is the platform level debugging where in if anything goes wrong with any package. For example, recently when I had set DEBUG=False, the backend was throwing HTTP 500. I was completely clueless what was happening. After deep debugging in the code, I figured out that 'compress js' that was being used in templates - it seemed was not being supported when DEBUG=False. It took some time to figure this out. Had there been a log or some mechanism, debugging would have been lot easier and quicker.

Dheerendra Rathor

unread,
Jan 6, 2016, 5:16:45 AM1/6/16
to Django users
What I do is to log things in log files. All exceptions are logged in error.log files and I've enabled admin mail which sends me an email whenever there is an exception. 
So basically logs and emails are quite helpful in debugging and makes it smooth. 

--
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 https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages