Debugging in VScode

I listened to the Django Chat podcast (highly recommend) with Nina Zakharenko. She gives a talk “Goodbye Print, Hello Debugger!” For me being new to Python/Django/HTML and coming from a Matlab background, I have sometimes struggled with debugging code with print(), especially in templates.

This talk is worth a watch, especially the latest PyCon 2020 and thought was worth highlighting. I use VScode and now have a debugger where I can see the full breakdown of variables even in templates. Now I just need to figure out why variables I thought were working have both DoesNotExist and MultipleObjectsReturned errors, but hey that’s a coffee, headphones, docs and google! Conditional breakpoints == awesome. I cannot begin to estimate how much time this will save.

I prefer IDE debugging, but she also gives options on command line debugging.

Few notes for VScode, for the first time running, make sure Python is selected as Interpreter before creating launch.json, then a django template should be listed.

Also it was a little fiddly getting debugging to work in templates. However File/Preferences/Settings/Features/Debug and set “Allow setting beakpoints in any file” worked for me.


Ah - thanks for this tip. I heard her mention this on the podcast but was confused when it didn’t work for me when I tried it. Looking forward to giving it a go.

1 Like