Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 97327

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

$
0
0

the context

I am debugging an application using Visual Studio Code (VSCode).

Breakpoints ARE NOT hit!

  • The breakpoints ARE NOT hit when I am using the launch.json (See [1])

  • I can debug with this launch.json (See [2]) but the debugger does not stops at the breakpoint !

I would like VSCode to stop on my breakpoints when necessary

**What is the correct configuration for launch.json to hit the breakpoints? **

Thank you for the time you are investing helping me!

the hierarchy of the project

  • launch.json
  • index.py See [4]
  • app.py See [3]
  • pages
    • index.py
    • transactions.py
  • launch.json is described here below [1]

the issue : Error: module 'index' has no attribute 'app.server'

The Error message is displayed after clicking on 'Start debugging > F5' = Error: module 'index' has no attribute '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" generates this error Error: A valid Flask application was not obtained from "index:app".

  • "FLASK_APP": "index.py" generates this error Error: Failed to find Flask application or factory in module "index". Use "FLASK_APP=index:name to specify one.

for information : gunicorn command (working)

here is a command available in azure-pipelines.yml running the plotly app :

  • gunicorn --bind=0.0.0.0 --timeout 600 index:app.server

attached files

[1] launch.json - non working

{
    "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

{
    "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 - root of the application

# -*- 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)

Viewing all articles
Browse latest Browse all 97327

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>