Click here to Skip to main content
15,843,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi forum,

atm, I'm able to
1) Use Visual Studio Code's debugger on my flask application and
2) serve clients that are not my development machine but
not both at the same time.

To use the debugger, I just hit "F5" from within VSCode. That runs the application and I can connect to it from the same machine with a browser calling

But calling my application from another machine in our LAN doesn't work
just ends in a timeout.

But if I start the app from the command-line
winpty python -m --host='' --port=80
, then I can connect to it from another machine in the LAN. And I cannot user breakpoints, variable inspection and such that way.

I want both. Just hit "F5", use breakpoints and see how application behaves while it serves requests from browsers on other machines.

You will have noticed the strange port specifications, haven't you?

I would like to serve port 80. Therefore in is this:
if __name__ == "__main__":
    #app.debug = False, host='', port=80)
But this port assignment doesn't seem to work. After all, a local browser reaches the application on port 5000.

How am I supposed to start this application in debugger and connect to it from remote?

What I have tried:

Tried the commented-out app.debug = False, sometimes with = True
Updated 8-Mar-22 21:21pm

1 solution

Got it.

That __name__ == "__main__" check fails when debugging because Visual Studio Code doesn't start directly but something called launcher instead. VSC also passes launcher some obscure arguments that tell it to start and debug In this situation, is not the main module and therefore doesn't execute code from that block.

Anyway, the Flask server does start. That's due to some of the obscure arguments, I suppose. And here we can turn the tides in our favour: We can configure that launcher via its launch.json configuration file. I now have this one:
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit:
    "version": "0.2.0",
    "configurations": [
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "",
                "FLASK_ENV": "development",
                "FLASK_DEBUG": "0"
            "args": [
//                "--no-debugger"
            "justMyCode": false,
            "jinja": true
The two lines after the single commented-out one are the addition that starts the Flask server the way we want it.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900