Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have become aware that the print statements in my django app are causing wsgi to error and fail. Without going over all my code and removing/commenting out the print statements, is there a way I can disable them when running wsgi. It needs to be a simple as possible.


share|improve this question
up vote 6 down vote accepted

Use WSGIRestrictStdout option:

WSGIRestrictStdout Off

or replace sys.stdout with sys.stderr in Django WSGI star script:

import sys
sys.stdout = sys.stderr

Writing To Standard Output

No WSGI application component which claims to be portable should write to standard output. That is, an application should not use the Python print statement without directing output to some alternate stream. An application should also not write directly to sys.stdout.

share|improve this answer
Excellent. Worked spot on. I used the second option. Thanks for your help – Designer023 Feb 24 '11 at 9:59
I have to disagree with the statement about logging to stdout. There are a lot of applications which adhere to the 12factor app principles – Lloyd Moore Nov 11 '15 at 7:43

In general, it is better to use logging for any kind of debug output in a web app and never use print statements at all. Or use them in the form:

print >> environ['wsgi.errors'], "message to be printed"

It is best to get rid of sys.stdout by making it a copy of sys.stderr just in case.

If you do development on a UNIX server, you can have two terminal windows open, one to run Django and the second one to do

tail -f loggingfile

And you get pretty much the same effect as using print statements, but you can use the standard logging module to generate the output, and in the production app, you just change the filter setting to not show DEBUG level messages.

share|improve this answer
In the future that sounds Ideal. I will try and add this to my code as I go through it. I knew I was doing it wrong when I started doing it, but it was just more to add to my learning curve. Thanks :D – Designer023 Feb 24 '11 at 10:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.