Files
KCGL/inventory-backend/app/__init__.py
2026-01-26 13:47:53 +08:00

26 lines
729 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from flask import Flask
from config import Config
from app.extensions import db, ma
def create_app():
app = Flask(__name__)
app.config.from_object(Config)
# 初始化插件
db.init_app(app)
ma.init_app(app)
# 【新增关键步骤】: 显式导入 models让 SQLAlchemy 认识所有的表
# 必须放在 db.init_app 之后create_all 或 蓝图注册 之前
from app import models
# 注册路由蓝图
from app.api.v1.stocks import stock_bp
app.register_blueprint(stock_bp, url_prefix='/api/v1')
# 【可选】如果你没有用 Flask-Migrate可以用下面这句话自动建表开发阶段
# with app.app_context():
# db.create_all()
return app