sqldump

(coffee) => code

Debugging Django

I was looking to accomplish a simple task – print debug messages in a Django View that would tell me what’s going on. Came across the following in a post:

You can configure it in your `settings.py`:

1
2
3
4
5
import logging
logging.basicConfig(
level = logging.DEBUG,
format = ''%(asctime)s %(levelname)s %(message)s'',
)

Then call it from any of your views:

1
2
3
def my_view(request):
import logging
logging.debug("A log message")

He then goes on to explain more advanced use cases using the Python Debugger, but this much was enough for what I was looking to do with it.