Logging a variable in Django for debugging

Eventually, you'll probably need to log a value for debugging. To do this in Django, you'll first need to import the logging library and create a new logger instance.

# import the logging library
import logging

# Get an instance of a logger
logger = logging.getLogger(__name__)

Then, when you need to output a value to the log for debugging, you can just add the line below.


more Django posts