flask click初始化数据库(flask 26)

2019-08-13 14:38:52 浏览数 (1)

app.py

from flask import Flask

import click from flask_sqlalchemy import SQLAlchemy

app = Flask(name) db = SQLAlchemy(app) @app.cli.command() @click.option('--drop', is_flag=True, help='Create after drop.') def initdb(drop): """Initialize the database.""" if drop: db.drop_all() db.create_all() click.echo('Initialized database.')

if name == 'main': app.run()

执行:

flask initdb

0 人点赞