如何使用Visual Code 2017调试python flask Webapp

时间:2019-03-10 07:55:03

标签: python debugging flask web-applications

我想知道如何使用VS Code调试flask网站应用程序吗?

首先:我具有以下结构

MainDirectory

-后端

  • backend.py

-前端

  • web_files
  • frontend.py

main_app.py

main_app_setings.cfg

我的服务器端口定义到main_app_setings.cfg文件中。 我的主文件是main_app.py,它是初始化整个应用程序并调用settings.cfg,backend.py和frontend.py。

我想调试frontend.py或backend.py

中定义的折点
@frontend.route('/index')
@nocache
def index_content():
context = {
    'title': "{}".format(flask.current_app.config['DISPLAY_TITLE']),
    'backend_url': flask.current_app.config['BACKEND_URL']
} 

return render_template('index.html', **context) # I want debug here

launch.json

"configurations": [
    {
        "name": "Flask",
        "type": "python",
        "request": "launch",
        "module": "flask",
        "env": {
            "FLASK_APP": "main_app.py",
        },
        "args": [
            "run",
            "--no-debugger",
            "--no-reload"
        ],
        "jinja": true
    }
]

当我通过Web浏览器单击按钮时,请让我们展示如何在可视代码环境中进行调试。

谢谢。

0 个答案:

没有答案