1、使用步骤:
创建蓝图
blue = Blueprint("myblue01", __name__)
使用蓝图装饰视图函数
@blue.route('/') def index(): return 'index'
将蓝图注册到app中
from appdemo_blueprint import blue app.register_blueprint(blue)
2、以包的形式使用蓝图
<1>user包之__init__.py:
from flask import Blueprint
userBlueprint = Blueprint('user', __name__)
from user import views
<2>user包之views.py:
from user import userBlueprint
@userBlueprint.route('/user')
def user_fun():
return 'user'
<3>appdemo.py:
from flask import Flask
from user import userBlueprint
app = Flask(__name__)
app.register_blueprint(userBlueprint)
if __name__ == "__main__":
print(app.url_map)
app.run(debug=True)