Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Flask app as a package in PyCharm

I was following this documentation on directory management for Flask projects. Now, I'm trying to run my flask application from PyCharm. I have added the below mentioned Environment Variables in Edit Configurations...:

FLASK_DEBUG=true

FLASK_APP=<absolute-path-to-root-directory-of-application>

I add the Script as flask run

enter image description here

The output running this configuration is this:

../red-flask/venv/bin/python "flask run"

../red-flask/venv/bin/python: can't open file 'flask run': [Errno 2] No such file or directory

Process finished with exit code 2

My project directory looks like:

/flask_app
    setup.py
    /flask_app
        __init__.py
        views.py
        /static
            style.css
        /templates
            layout.html
            index.html
            login.html
            ...

I am unable to figure out how to make this work, any help is appreciated.

like image 247
shubhamsingh Avatar asked Aug 17 '17 17:08

shubhamsingh


1 Answers

This is documented in the development build of the docs.

You need to point to the location of the flask command.

  • Script: /path/to/env/bin/flask
  • Script parameters: run

Until 1.0 comes out, you need to point FLASK_APP at __init__.py if you don't install your package in your env.

  • Environment variables: FLASK_APP /path/to/flask_app/__init__.py

Preferably, install the package in the env and point to it using the import name.

  • From the terminal, in the virtualenv: pip install -e .
  • Environment variables: FLASK_APP flask_app
like image 173
davidism Avatar answered Oct 01 '22 02:10

davidism