0 votes
1 view
in Python by (47.8k points)

So, I started learning to code in Python and later Django. The first time it was hard looking at tracebacks and actually figure out what I did wrong and where the syntax error was. Some time has passed now and some way along the way, I guess I got a routine in debugging my Django code. As this was done early in my coding experience, I sat down and wondered if how I was doing this was ineffective and could be done faster. I usually manage to find and correct the bugs in my code, but I wonder if I should be doing it faster?

I usually just use the debug info Django gives when enabled. When things do end up as I thought it would, I break the code flow a lot with a syntax error and look at the variables at that point in the flow to figure out, where the code does something other than what I wanted.

But can this be improved? Are there some good tools or better ways to debug your Django code?

1 Answer

0 votes
by (107k points)

For debugging in Django there are many ways, but the most straightforward way is simply to use the Python debugger. To do so just add the following line into a Django view function:-

import pdb;

pdb.set_trace()

If you are using Python 3.7 then you can use the following function:-

breakpoint()

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...