简体   繁体   English

如何在 Flask 项目的 VSCode 中调试 JavaScript?

[英]How to debug JavaScript in VSCode on a Flask project?

I have a similar question to this unanswered one .我有一个与这个未回答问题类似的问题。 I am not yet allowed to comment on said question.我还不能对上述问题发表评论。

Is it possible, and if so, how can I debug the JS components of my Flask app from within VSCode?是否可能,如果可以,我如何从 VSCode 中调试我的 Flask 应用程序的 JS 组件?

I have the following debug configuration:我有以下调试配置:

"version": "0.2.0",
"configurations": [
    {
        "name": "Python: Flask - Dev",
        "type": "python",
        "request": "launch",
        "module": "flask",
        "env": {
            "PIPENV_VENV_IN_PROJECT":"1",
            "FLASK_APP":"run.py",
            "FLASK_ENV":"development",
            "FLASK_DEBUG":"1",
            "TEMPLATES_AUTO_RELOAD" : "1"
            
        },
        "args": [
            "run"
        ],
        "jinja": true
    },
    {
        "name": "Python: Flask - initDB",
        "type": "python",
        "request": "launch",
        "module": "flask",
        "env": {
            "PIPENV_VENV_IN_PROJECT": "1",
            "FLASK_APP": "run.py",
            "FLASK_ENV": "development",
            "FLASK_DEBUG": "1",
        },
        "args": [
            "run",
            "--no-reload" // Use for initial dev DB deploy
        ],
        "jinja": true
    }
]

From what I gather, it is possible to use the remote debugging feature of Firefox Developer Edition with its own configurations as per here .据我所知,可以使用 Firefox Developer Edition 的远程调试功能及其自己的配置,如下所示

Any ideas on how to combine these configurations?关于如何组合这些配置的任何想法? Or perhaps another solution to the problem altogether?或者也许是另一种解决问题的方法?

I know this is late, but I thought I'd leave this here for others.我知道这已经晚了,但我想我会把它留给其他人。

For me it was a matter of setting the "webRoot" property correctly.对我来说,这是正确设置“webRoot”属性的问题。 Here is my configuration这是我的配置

    {
        "type": "pwa-chrome",
        "request": "launch",
        "name": "Launch Chrome",
        "url": "http://localhost:5001/",
        "webRoot": "${workspaceFolder}/wserver",
    }

"webRoot" should point to the root directory that the server loads. “webRoot”应该指向服务器加载的根目录。 Open the page/app you are trying to debug and look in the Sources tab in developer tools to see the root web directory.打开您尝试调试的页面/应用程序,并在开发人员工具的“源”选项卡中查看根目录 web。

Given the tree in the Sources tab looks like the following;给定 Sources 选项卡中的树如下所示; "webRoot" should point to the local parent directory of (in my case) the static folder. “webRoot”应该指向(在我的例子中)static 文件夹的本地父目录。 In my case "wserver"在我的例子中是“wserver”

Local directory path:本地目录路径:

FlaskApp/wserver/static/scripts/myscript.js

DevTools Sources tree: DevTools 源代码树:

> localhost:5001
  > static
    > scripts
      > myscript.js

As of the latest version of vscode you don't need to install any extra extensions.从最新版本的 vscode 开始,您不需要安装任何额外的扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM