[Answered ]-Having trouble with my views and formsets saving

2đź‘Ť

âś…

Since you’re here to learn, and your code is quite complex (I’d need all the code necessary to reproduce your problem, which includes models), I’m not going to answer with a code fix.

Instead, you will learn how to use a debugger, which will fix “I still don’t know where I am going wrong”.

  1. Install ipdb, because it’s more convenient than just pdb, pip install ipdb.

  2. Set a breakpoint, in your view, add this line import ipdb; ipdb.set_trace().

  3. Run the code in the devserver, the devserve should pause at the breakpoint, and show the code it’s paused at.

  4. Get to know ipdb, type “h”, it will show a list of command, try to overread the documentation of each command, you can also check this article which includes a video.

  5. Step through your code, by typing “n” in the debugger, the interpreter should move to the next line of code, “d” to step in, “u” to step out, etc … You can execute Python from the prompt at any time.

You will know what Python is doing exactly, fixing “I still don’t know where I am going wrong”. Also, you’ll become an invincible programmer (or something like that hahaha)

👤jpic

Leave a comment