Flask使用蓝图管理APP模块
在cars模块下创建一个新的子模块文件夹
在cars文件夹下新建一个python package,保存为api_1_0
创建和注册蓝图
在这个文件夹中添加
from flask import Blueprint
# create blueprint
api=Blueprint('api_1_0',__name__)
创建蓝图
转回到cars文件夹下的__init()__.py文件下
在createapp()方法中添加注册字段
def create_app(config_name):
# it will use different setting object decide by runnable mode
app = Flask(__name__)
# load config file,which define as an object
app.config.from_object(config[config_name])
#operate handle of database how to connect to app
db.init_app(app)
Session(app)
csrf.init_app(app)
global redis_store
redis_store=redis.StrictRedis(host=config[config_name].REDIS_HOST,port=config[config_name].REDIS_PORT)
# register blueprint
from cars.api_1_0 import api
app.register_blueprint(api,url_prefix=&