【发布时间】:2019-11-01 13:01:05
【问题描述】:
上下文
我正在使用 Visual Studio Code (VSCode) 调试应用程序。
- 应用主要依赖https://plot.ly、https://palletsprojects.com/p/flask、https://pandas.pydata.org/和https://numpy.org/
没有击中断点!
当我使用 launch.json 时没有命中断点(参见 [1])
我可以使用这个 launch.json 进行调试(参见 [2]),但调试器不会在断点处停止!
我希望 VSCode 在必要时停止我的断点
**launch.json 下断点的正确配置是什么? **
感谢您投入时间帮助我!
项目的层次结构
- launch.json
- index.py 见 [4]
- app.py 见 [3]
- 页
- index.py
- transactions.py
- launch.json 如下所述 [1]
问题:错误:模块 'index' 没有属性 'app.server'
点击“开始调试> F5”后显示错误消息= 错误:模块'index'没有属性'app.server'
我尝试了几十种方法来设置 "FLASK_APP": "index:app.server",但它们会生成不同的错误消息:
"FLASK_APP": "index:app.server" 生成此错误 错误:未从 "index:app" 获得有效的 Flask 应用程序。
“FLASK_APP”:“index.py” 生成此错误 错误:无法在模块“index”中找到 Flask 应用程序或工厂。使用 "FLASK_APP=index:name 指定一个。
信息:gunicorn 命令(工作)
这是azure-pipelines.yml 中运行plotly 应用程序的命令:
gunicorn --bind=0.0.0.0 --timeout 600 index:app.server
附加文件
[1] launch.json - 不工作
{
"version": "0.2.0",
"configurations": [
{
"name": "Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "index:app.server",
"FLASK_ENV": "development",
"FLASK_DEBUG": "1",
"FLASK_RUN_PORT": "8052"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true
}
]
}
[2] launch.json - 工作但没有命中断点
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${workspaceRoot}\\index.py",
"console": "integratedTerminal"
}
]
}
[3] webapp.py
># -*- coding: utf-8 -*-
import dash
app = dash.Dash(
__name__, meta_tags=[{"name": "viewport",
"content": "width=device-width, initial-scale=1"}]
)
server = app.server
app.config.suppress_callback_exceptions = True
index.py - 应用的根目录
# -*- coding: utf-8 -*-
import dash_html_components as html
import dash_core_components as dcc
from webapp import app
from dash.dependencies import Input, Output
from pages import (
transactions, index)
# Describe the layout/ UI of the app
app.layout = html.Div([
dcc.Location(id="url", refresh=False),
html.Div(id="page-content")
])
# Update page
@app.callback(Output("page-content", "children"),
[Input("url", "pathname")])
def display_page(pathname):
if pathname == "/dash/index":
return index.layout
if pathname == "/dash/transactions":
return transactions.layout
else:
return index.layout
if __name__ == "__main__":
app.run_server(debug=True, port=8051)
【问题讨论】:
标签: python visual-studio-code plotly-dash vscode-debugger