简体   繁体   English

FLASK:plotly:错误:模块“索引”没有属性“app.server”

[英]FLASK : plotly : Error: module 'index' has no attribute 'app.server'

the context上下文

I am debugging an application using Visual Studio Code (VSCode).我正在使用 Visual Studio Code (VSCode) 调试应用程序。

Breakpoints ARE NOT hit!没有击中断点!

  • 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!感谢您投入时间帮助我!

the hierarchy of the project项目的层次结构

  • launch.json发射.json
  • index.py See [4] index.py 见[4]
  • app.py See [3] app.py 见 [3]
  • pages页面
    • index.py索引.py
    • transactions.py交易.py
  • launch.json is described here below [1] launch.json 描述如下 [1]

the issue: Error: module 'index' has no attribute 'app.server'问题:错误:模块'index'没有属性'app.server'

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 指定一个。

for information: gunicorn command (working)信息:gunicorn 命令(工作)

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

attached files附加的文件

[1] launch.json - non working [1] 启动.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 - working but breakpoints are not hit [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 [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 - root of the application 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)

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.

相关问题 Gunicorn 20 在 'index' 中找不到应用程序 object 'app.server' - Gunicorn 20 failed to find application object 'app.server' in 'index' Flask AttributeError:模块“app”没有属性“run” - Flask AttributeError: module 'app' has no attribute 'run' 运行 docker 时无法将“app.server”解析为属性名称或 function 调用 - Failed to parse 'app.server' as an attribute name or function call when running docker AttributeError:模块'plotly'没有属性'plotly' - AttributeError: module 'plotly' has no attribute 'plotly' 在gunicorn上部署flask应用程序,模块对象没有属性 - Deploying flask app on gunicorn, module object has no attribute 使用 Plotly 最新版本并出现错误:模块 'plotly.validators.layout' 没有属性 'ExtendtreemapcolorsValidator' - Using Plotly latest version and getting error : module 'plotly.validators.layout' has no attribute 'ExtendtreemapcolorsValidator' 烧瓶蓝图属性错误:“模块”对象没有属性“名称”错误 - Flask Blueprint AttributeError: 'module' object has no attribute 'name' error Flask-Login 模块“app”没有属性“after_request” - Flask-Login module 'app' has no attribute 'after_request' 情节:熊猫数据框错误:模块“plotly.express.data”没有属性 - Plotly: Error with pandas dataframe: module 'plotly.express.data' has no attribute AttributeError:模块“tensorflow”没有属性“app”:错误 - AttributeError: module 'tensorflow' has no attribute 'app': error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM