安装
pip install flask-blueprint
项目拆分
- ① views.py中创建
from flask import Blueprint
blue = Blueprint('first',__name__)
- ② 在__init__.py中注册
from flask import Flask
from APP.views import blue
def create_app():
app = Flask(__name__)
app.register_blueprint(blueprint=blue)
return app
- ③ 在views.py中调用蓝图进行注册
@blue.route('/')
def hello_world():
return 'Hello World!'
- ④ 在manager中
from flask_script import Manager
from APP import create_app
app = create_app()
manager = Manager(app)
if __name__ == '__main__':
manager.run()