[英]FLASK : plotly : Error: module 'index' has no attribute 'app.server'
I am debugging an application using Visual Studio Code (VSCode).我正在使用 Visual Studio Code (VSCode) 调试应用程序。
The breakpoints ARE NOT hit when I am using the launch.json (See [1])当我使用 launch.json 时,断点未命中(参见 [1])
I can debug with this launch.json (See [2]) but the debugger does not stops at the breakpoint !我可以用这个launch.json(参见[2])进行调试,但调试器不会在断点处停止!
I would like VSCode to stop on my breakpoints when necessary我希望 VSCode 在必要时停止我的断点
**What is the correct configuration for launch.json to hit the breakpoints? **launch.json 的正确配置是什么? **
**
Thank you for the time you are investing helping me!感谢您投入时间帮助我!
- launch.json
发射.json
- index.py See [4]
index.py 见[4]
- app.py See [3]
app.py 见 [3]
- pages
页面
- index.py
索引.py
- transactions.py
交易.py
The Error message is displayed after clicking on 'Start debugging > F5' = Error: module 'index' has no attribute 'app.server'单击“开始调试> F5”后显示错误消息=错误:模块“索引”没有属性“app.server”
I tried dozens of ways to set the "FLASK_APP": "index:app.server" but they generate diverse error messages:我尝试了几十种方法来设置"FLASK_APP": "index:app.server"但它们会生成各种错误消息:
"FLASK_APP": "index:app.server" generates this error Error: A valid Flask application was not obtained from "index:app". “FLASK_APP”:“index:app.server”生成此错误错误:未从“index:app”获取有效的 Flask 应用程序。
"FLASK_APP": "index.py" generates this error Error: Failed to find Flask application or factory in module "index". “FLASK_APP”:“index.py”生成此错误错误:无法在模块“index”中找到 Flask 应用程序或工厂。 Use "FLASK_APP=index:name to specify one.
使用 "FLASK_APP=index:name 指定一个。
here is a command available in azure-pipelines.yml
running the plotly app:这是运行 plotly 应用程序的
azure-pipelines.yml
中可用的命令:
gunicorn --bind=0.0.0.0 --timeout 600 index:app.server
{
"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
}
]
}
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${workspaceRoot}\\index.py",
"console": "integratedTerminal"
}
]
}
# -*- 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
# -*- 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)
Your [1] example isn't working because you set FLASK_APP
to index:app.server
which tries to find an attribute named app.server
on the index
module.您的 [1] 示例不起作用,因为您将
FLASK_APP
设置为index:app.server
,它试图在index
模块上查找名为app.server
的属性。 Attribute names can't have a dot (you can verify this by importing that module and trying out getattr(index, "app.server")
).属性名称不能有点(您可以通过导入该模块并尝试
getattr(index, "app.server")
来验证这一点)。 You should be able to make FLASK_APP
simply say index
to have it work.你应该能够让
FLASK_APP
简单地说index
让它工作。
See the Flask documentation on app discovery for more details.有关更多详细信息,请参阅有关应用程序发现的 Flask 文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.