'Flask application doesn't take into account the arguments in app.run()?

I have this issue : I use arguments to set the port and the debugger on like this

if __name__ == '__main__':
    app.run(port=4200, debug=True)

but it isn't taken into account when I click on the run button (I use Pycharm pro and the project I create is a Flask Project)

The terminal shows this :

FLASK_APP = app.py
FLASK_ENV = development
FLASK_DEBUG = 0
In folder $FOLDERPATH
$PATH\python.exe -m flask run
 * Serving Flask app 'app.py' (lazy loading)
 * Environment: development
 * Debug mode: off
 * Running on http://127.0.0.1:5000 (Press CTRL+C to quit)

Any ideas ?



Solution 1:[1]

Your call to app.run is only relevant when __name__ == __main__...that is, when your code is the main entrypoint. But as you can see from the terminal output, Pycharm isn't calling python app.py, it is in fact calling:

python -m flask run

In this case, the flask module is the main entrypoint, and you would control things like the port or debug mode through environment variables (like FLASK_DEBUG) or command line parameters (python -m flask run --port 4200).

According to the pycharm documentation, you can see command line parameters for the flask run command using the "Additional options" field.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 larsks