python - 在 Visual Studio Code 中调试 Flask (Python) Web 应用程序

标签 python visual-studio-code

如何配置 Visual Studio Code 以调试 Flask (Python) 网络应用程序?

例如,当我在 View 函数中设置调试器时,它应该允许我在浏览器中点击该路由时单步执行该函数。

我已经在 Visual Studio Code 中安装了 Python 扩展。

最佳答案

这是我对 Flask 0.12、Python 3.6 和 Visual Studio Code 1.20 的配置

// File "launch.json"
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Flask",
            "type": "python",
            "request": "launch",
            "stopOnEntry": false,
            "pythonPath": "${config:python.pythonPath}",
            "program": "${workspaceRoot}/app.py",
            "env": {
                "FLASK_APP": "${workspaceRoot}/app.py"
            },
            "args": [
                "run"
            ],
            "envFile": "${workspaceFolder}/.env",
            "debugOptions": [
                "RedirectOutput"
            ]
        }
    ]
}

# app.py file
app.run(port=5000)
# Don't use debug=True, because it disables the Visual Studio Code debugger
# app.run(port=5000, debug=True) - disables the Visual Studio Code debugger

关于python - 在 Visual Studio Code 中调试 Flask (Python) Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39056448/

相关文章:

python - 可哈希类与 Python 中的 Enum 的交互

不要进入 vscode 工作区设置用户设置

c++ - 如何在 GCC 的 VSCode 中设置 wxWidgets?

javascript - 如何使 VSCode 在导入中解析 "@"

python - 如何将 dict 转换为 unicode JSON 字符串?

python - 迭代字典 x 次

javascript - 检测到但未使用的 VScode sourceMaps

javascript - 由于缺少绿色灯泡,无法在 Visual Studio 中自动创建 jsconfig.json

python - Azure kubernetes - python 读取configmap?

python - 对两个黑白图像进行异或求和