This section will instruct you on how to attach a debugger to your container.
No need to start an entirely new server or environment, just use the already running container 😃
You should probably make a View before doing this in order to have something to debug.
NOTE:
- The docker-compose config and VSCode are already configured to expect a process on port
5678
.- Because of hot-reload, the debugger process will be shutdown whenever there are changes in the container. You must start re-attach VSCode to continue debugging the "new" code.
Table of contents:
- Step 1: Install debugger
- Step 2: Initialize debugger
- Step 3: Start VSCode debug session
- Step 4: Set breakpoint
Install debugpy
inside the virtual environment of container clean
.
Solution
From root of project on host machine:
docker compose exec clean pipenv install debugpy
Attach a debugger to the django server.
Use host 0.0.0.0
with port 5678
.
Initialize inside the file clean/root/wsgi.py
.
Solution
See debugpy.py and wsgi.py in solution.
Go to the debug tab in VSCode in the left sidebar.
At the top you can select which configuration you want to use (see launch.json).
Select the one for clean
, the editor should now be orange.
If you some other editor than VSCode, you must configure it yourself. The process is running as mentioned on port
5678
, so in theory anything can listen to it.
Set a breakpoint 🔴 on a line of code you want to inspect. Preferably inside a View so that you can trigger a request to that endpoint.
👈 Back to Tasks