I want to run some commands from terminal with 'flask' command but it isn't working.
The Following is my project structure-
FlaskUserAuthentication
├── FlaskUserAuthentication
│ ├── API
│ │ ├── __init__.py
│ │ ├── db_models.py
│ │ └── routes.py
│ ├── Site
│ │ ├── __init__.py
│ │ ├── routes.py
│ │ ├── static
│ │ │ └── form_style.css
│ │ └── templates
│ │ └── Site
│ │ ├── base_layout.html
│ │ ├── index.html
│ │ ├── logout.html
│ │ ├── profile.html
│ │ ├── signin.html
│ │ └── signup.html
│ ├── __init__.py
│ └── commands.py
├── run.py
└── venv
As the flask run
command runs the app, I am sure that my environment variable is set properly. However, when I try to use flask-cli-command like-
flask create_db
I get, Error: No such command "create_db".
The following is my FlaskUserAuthentication/commands.py
file-
from FlaskUserAuthentication import app, db
from FlaskUserAuthentication.API.db_models import Group, Member, Project, Milestone
@app.cli.command('create_db')
def createDatabase():
db.create_all()
print('***** Datebase created ****')
#....some more commands
and the FlaskUserAuthentication/__init__.py
module (where the Flask app instance is initiated)-
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SECRET_KEY'] = 'justasamplekey'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
db = SQLAlchemy(app)
from FlaskUserAuthentication.API.routes import api
from FlaskUserAuthentication.Site.routes import site
app.register_blueprint(api)
app.register_blueprint(site)
flask --help
It shows you all the commands registered underflask cli
. Moreover, yourCLIGroup
should be executed in therun.py
where I assume you are running the server. – Etui