So, I started learning to code in Python and later Django.The first times it was hard looking at tracebacks and actually figure out what I did wrong and where the syntax error was.I’ll insert the following at the point I want to set the trace.(Epdb) request.session.session_key 'i31kq7lljj3up5v7hbw9cff0rga2vlq5' (Epdb) list 85 raise some_error.However there are other options suggested by others (I won’t recommend them): But the Python Debugger (pdb) is highly recommended for all types of Python code.If you are already into pdb, you’d also want to have a look at IPDB that uses ipython for debugging. A useful reference provided by Seafangs : Using the Python debugger in Django I really like Werkzeug‘s interactive debugger.This sets a trace and serves this on a local port that you can connect to.
It cost me a little but I have to say the advantage that I get out of it is priceless.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. Are there some good tools or better ways to debug your Django code?If you try to load that page in your browser, the browser will hang and you get a prompt to carry on debugging on actual executing code.Custom Error() 86 87 # Example login view 88 def login(request, username, password): 89 import epdb; epdb.serve() 90 - And tons more that you can learn about typing epdb help at any time. I threw it in here to demonstrate how you can use this to debug something other than a local instance, like a development server on your local LAN.If you want to serve or connect to multiple epdb instances at the same time, you can specify the port to listen on (default is 8080). Obviously, if you do this be careful that the set trace never makes it onto your production server!