Forums

How to open Flask Shell on CLI

I am following this Tutorial :- https://scotch.io/tutorials/build-a-crud-web-app-with-python-and-flask-part-three

I am trying to open the Flask Shell to run flask commands as per the tutorial. Its giving error .

05:42 ~/project-dream-team-three (master)$ flask shell
Usage: flask shell [OPTIONS]
Error: Could not locate Flask application. You did not provide the FLASK_APP environment variable.

I have to setup the following Commands using flask shell :-

$ flask shell
>>> from app.models import Employee
>>> from app import db
>>> admin = Employee(email="admin@admin.com",username="admin",password="admin2016",is_admin=True)
>>> db.session.add(admin)
>>> db.session.commit()

you have to set the FLASK_APP environment variable. I think they mention that earlier on in the tutorial -- you need to do it once per Bash console you open, so maybe you did it in an old console?

export FLASK_APP=run.py
flask shell