Where do things go when I ‘print’ them from my Django app?

The output should be in the terminal, where django was started. (if you don't started it directly, I don't believe there's a way to read it)

As linkedlinked pointed out, it's the best to not use print, because this can cause Exceptions! But that's not the only reason: There are modules (like logging) made for such purposes and they have a lot more options.

This site (even when it's from 2008) confirm my statements:

If you want to know what’s going on inside a view, the quickest way is to drop in a print statement. The development server outputs any print statements directly to the terminal; it’s the server-side alternative to a JavaScript alert().

If you want to be a bit more sophisticated with your logging, it’s worth turning to Python’s logging module (part of the standard library). You can configure it in your settings.py: here he describes, what to do (look on the site)

For debugging-purposes you could also enable the debug-mode or use the django-debug-toolbar.

Hope it helps! :)


Never use print, as once you deploy, it will print to stdout and WGSI will break.

Use the logging. For development purposes, is really easy to setup. On your project __init__.py:

import logging
from django.conf import settings

fmt = getattr(settings, 'LOG_FORMAT', None)
lvl = getattr(settings, 'LOG_LEVEL', logging.DEBUG)

logging.basicConfig(format=fmt, level=lvl)
logging.debug("Logging started on %s for %s" % (logging.root.name, logging.getLevelName(lvl)))

Now everything you log goes to stderr, in this case, your terminal.

logging.debug("Oh hai!")

Plus you can control the verbosity on your settings.py with a LOG_LEVEL setting.

Tags:

Python

Django