Got it.
That
__name__ == "__main__"
check fails when debugging because Visual Studio Code doesn't start
app.py directly but something called
launcher instead. VSC also passes launcher some obscure arguments that tell it to start and debug app.py. In this situation, app.py 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:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "app.py",
"FLASK_ENV": "development",
"FLASK_DEBUG": "0"
},
"args": [
"run",
"--host=0.0.0.0",
"--port=80"
],
"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.