Digging into Django class

Django uses python classes for pretty much all major components that you will interact with (Models, Forms, Views, Querysets, etc.) and a lot of these have predefined methods for doing certain things, eg saving a model or processing a POST request. While this may seem like a lot of magic (and in some places there is some impressive stuff going on), it does make it very easy to jump in to work out what is going on.

I cannot count the times I have done this (especially on Generic Views):


class MyView(FormView):
  # ...
  def form_invalid(self, form):
    print(form.errors)
    return super().form_invalid(form)

This quick override allows me to see if the processed form has any errors and as a result not taking the expected action, or overriding a model save method instead of signals which are hard to follow.

The key thing to remember with Django is that it's just Python, so any Python debugging trick you know or read about ought to work in Django (within reason of course!)