Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k 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 (106k 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()

Browse Categories

...