Debugging

VS Code

In VS Code, you can create a launch.json file that allows you to add breakpoints and step through your API code. Here are the steps:

  1. Open your project in VS Code.
  2. Click the debug menu on the sidebar.
  3. Click create a launch.json file

Set up launch.json

  1. Choose Python as the language.
  2. I typically choose Python File as the template, and then just add the following to the configuration.
{
    "configurations": [
        {
            "name": "Dev Ngrok",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "app:create_app('Ngrok')",
                "FLASK_ENV": "development",
                "FLASK_DEBUG": "0"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ]
        }
    ]
}

  1. The debug configuration should now show up in the debug menu on the sidebar. Now you can add break points to your code and click the Green Triangle button to run your flask application.

Run the debug configuration

If you want to run the application with a different configuration mode, you can replace the Ngrok in app:create_app('Ngrok') with any other config mode.

You can learn more about the VS Code debugger here and more about debugging Python applications here