2

How to set up a Run configuration for flask App in Pycharm Community on Windows? I found Flask.exe for Flask after installing on venv/Script but yet there should be a way to execute it using a Flask Python script to make it work with the default Python Run configuration.

Pycharm Run configuration

gerosalesc
  • 2,983
  • 3
  • 27
  • 46

2 Answers2

2

Make a file app.pyand add the code:

from flask import Flask

app = Flask(__name__)


@app.route('/')
def hello_world():
    return 'Hello World!'


if __name__ == '__main__':
    app.run()

Then open a cmd in the app.py folder and run in console flask run or start it from PyCharm Screen

Cristian
  • 37
  • 1
  • 8
1

Add the following to your Python file where the Flask app is defined:

if __name__ == '__main__':
    app.run()

And setup your configuration to run that script.

You can read more about this method of running flask app in the docs. Remember that it is not a suitable way to run Flask apps in production (and neither is flask.exe).

Mikhail Burshteyn
  • 4,762
  • 14
  • 27