Flask 学习笔记(六)-插件拓展库flask-blueprint

flask-blueprint 蓝图

  • 安装: pip install flask-blueprint

创建新项目
Flask 学习笔记(六)-插件拓展库flask-blueprint_第1张图片
vi manage.py

from flask import Flask
from flask_script import Manager
from App.views import blue

app = Flask(__name__)
app.register_blueprint(blueprint=blue)
manager = Manager(app=app)

if __name__ == '__main__':
    manager.run()

vi App/views.py

from flask import Blueprint
blue = Blueprint('first_blue', __name__)

@blue.route('/')
def single_flask():
    return "Hello Blueprint"

vi run.sh

python manage.py runserver -d -r -h 0.0.0.0

启动: bash run.sh
地址: http://127.0.0.1:5000/
使用bule即可将项目简单拆分为类似于Django的MVT结构

源码地址:https://github.com/565785929/StudyFlask/tree/master/d06

你可能感兴趣的:(python,Flask,Flask学习之路)