我想使用“ flask”命令从终端运行一些命令,但是它不起作用。
以下是我的项目结构-
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
在flask run
命令运行该应用程序时,我确定我的环境变量设置正确。但是,当我尝试使用flask-cli命令之类的
flask create_db
我明白了,Error: No such command "create_db".
以下是我的flaskUserauthentication/commands.py
文件-
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
和flaskUserauthentication/__init__.py
模块(在其中启动flask应用实例的模块)-
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)