Python’s breakpoint() function opens its debugger, pdb, which pauses the program and allows you to inspect and modify things. Let’s look at an example of using it within a Django view, from a sample project included in Boost Your Django DX.
This page, “Party Central”, lists animals with their pizza preferences and whether they’re hungry. Underneath the table are two filter buttons, “Hungry” and “Satiated”, which allow you to select only animals with those hunger levels.
Unfortunately, the filter buttons are broken. Click “Hungry” to load http://localhost:8000/?hungry=1 and we see the same list of animals:
The hungry URL parameter is there, and the button is highlighted, but the data isn’t filtered. Let’s use pdb to figure out why.
We can run pdb with the breakpoint() function, a Python built-in that opens the configured debugger (which is pdb by default). Let’s add it to the view function, before it renders the template.