The Debug feature is one of the most powerful features available inside VS Code. This section we will learn how to configure debug, we will launch our Python Flask demo application in Debug mode, insert breakpoints to help us troubleshoot, and finally troubleshoot and fix our application.
In the lab we will launch our Python Flask demo application in Debug mode.
- Copy the
Dockerfile
in the root of the project to04-power-user
directory - Navigate to the
04-power-user
folder - Click and open
app.py
- On line 10 we want to add an extra
s
to images so it breaks our application like:
imagess = [
- Launch the debugger. On the left tool bar click the Triangle and Bug icon
- At the top of the Debug screen click the Green Triangle to start debug
- Our application will automatically launch in the browser
Now, we will start debugging why our application is not starting by inserting break points and watch variables.
- Navigate to the
04-power-user
folder - Click and open
app.py
- To the left of line 23 hover with your mouse and you will see a red dot appear (Breakpoint). Click the red dot to create a breakpoint.
- Open the Debug screen (Triangle with the bug) and hover over the
WATCH
section and click the+
- Type
images
for the Expression to watch
- Start Debug Click Green Triangle at the top of Debug screen
- Review the
Variable
andWATCH
screen output. You should notice theimagess
variable is captured and shows the images while theWATCH
returns an error.
Now, we have the information to repair our demo app. Let's make the fix and rerun debug.
- Navigate to the
04-power-user
folder - Click and open
app.py
- Fix the
images
variable on line 10 as follows:
images = [
- Open the Debug screen again
- Start Debug
- We should now see the variables populate in the
WATCH
window - Once we see the
images
variable works we can remove thebreakpoint
in theapp.py
file on line 23 by clicking the red dot. - Rerun Debug
- Celebrate for fixing our application!