I am new to a huge code base, and to better understand what is going on, I would love to see every line which gets executed during one http request.
similar to set -x
on the shell.
I would like to exclude the details of the python standard library and of the django framework. I would like to see only my code.
I googled a bit. I found this debug-toolbar-plugin, but it is unclear how to install it:
Is there a simple way to print every line of my code which gets executed during a http request?
This is only needed for development (runserver).
If you want to see how a particular piece of code is executed you can use breakpoint() in the code which will give you a pbd shell:
breakpoint() is cool, but does not help me in my current context. I am new to a huge legacy code base, and i have no clue which view method handles this request.
BTW, I found a way to install the django-debug-toolbar-line-profiler. See: How to install this fork? · Issue #5 · mikekeda/django-debug-toolbar-line-profiler · GitHub
Nevertheless I am curious how you would solve this (log/print/trace all lines which get executed during a http request)
I would use the inspection tool of the browser and see to which urls it connects. The endpoint has to be somewhere in urls.py
- this will lead to the view that is used. From there I would look up which Models are involved or which other methods are used.
There could be some Middleware involved but this must be listed in the settings.py
file and all request will go through it.
Yeah so in short: Find out which URLs are triggered; look them up in the project and find the associated views to them. This will lead to Models, Functions and Templates that are used. Debug them with Tests and Breakpoints.
This project sounds interesting.
You really don’t want to do that (print all lines which get executed during an http request). The volume of output, and the interleaving of code from all the function calls would be too much to try to comprehend when you include all the Django and Python libraries involved.
I agree with the answer from @theRealBithive - the easiest way to start understanding this is start from the root urls.py file identified in the settings, and see where the chain of events takes you from there.
Python Hunter has a cool simple domain-lanuage for filtering lines. So you can easily trace only the lines you are interested in.
1 Like