def initdb(drop): """初始化数据库表的 schema""" if drop: # 如果命令为 initdb --drop, 删除所有表并重新建立 db.drop_all() # 普通情况下 initdb 创建数据库表 db.create_all() click.echo('Initialized database.')
def _app(request): app = create_app('test') app.config['DEBUG'] = True app.config['TESTING'] = True with Postgresql() as postgresql: app.config['SQLALCHEMY_DATABASE_URI'] = postgresql.url() with app.app_context(): db.init_app(app) db.create_all() populate(db) yield app
def index(): db.create_all() return render_template("index.html")
def current_user(): db.create_all() uid = session.get('user_id', '') u = User.one(id=uid) return u
UserSearchController, UserRecipesController, UserRecipeController, LoginController, RecipesController, RecipesShowController, RecipeSearchController, InstructionsController, IngredientsController, ) app = Flask('yummy_recipes_api') app.config.from_object('settings.DevEnv') db.app = app db.init_app(app) db.create_all() api = Api(app) migrate = Migrate(app, db) CORS(app) # Enable CORS on all our endpoints api.add_resource(UsersController, '/users/') api.add_resource(UsersShowController, '/users/<int:user_id>/') api.add_resource(UserRecipesController, '/users/<int:user_id>/recipes/') api.add_resource(UserRecipeController, '/users/<int:user_id>/recipes/<int:recipe_id>/') api.add_resource(LoginController, '/login/') api.add_resource(RecipesController, '/recipes/') api.add_resource(RecipesShowController, '/recipes/<int:recipe_id>/') api.add_resource(InstructionsController, '/instructions/') api.add_resource(IngredientsController, '/ingredients/')
def init_db(): app = create_app() with app.app_context(): db.init_app(app) db.create_all()
def run(): db.create_all()