1.定義藍圖
from flask import Blueprint
api_ctl_bp = Blueprint("api", __name__, url_prefix="/api")
2.路由中使用藍圖
@api_ctl_bp.route('/hello', methods = ['get'])
def hello():
return 'hello'
3.註冊藍圖
app = Flask(__name__)
app.register_blueprint(api_ctl_bp)
這裏注意,如果定義藍圖和使用藍圖的不是同一個py文件,則必須把使用藍圖的文件也import進來,否則服務起來是不能找到藍圖的。