一、示例代码
run.py
from app import create_app if __name__ == '__main__': app = create_app() app.run(debug=True, port=5000)
__init__.py
from flask import Flask from app.controllers import config_blueprint def create_app(): app = Flask(__name__) # 注册蓝图 config_blueprint(app) return app
controllers / __init__.py
from .IndexController import home from .AdminController import admin # 蓝本默认配置 default_blueprint = ( # (蓝本,前缀) (home, ''), (admin, '/admin') ) # 封装函数配置蓝本 def config_blueprint(app): for blueprint, url_prefix in default_blueprint: app.register_blueprint(blueprint, url_prefix=url_prefix)
controllers / AdminController.py
from flask import Blueprint, render_template admin = Blueprint("admin", __name__, url_prefix="", template_folder="templates") @admin.route('/index') @admin.route('/', methods = ['GET']) def index(): return render_template('admin/index.html')
标签:__,blueprint,Flask,app,蓝图,admin,模块,import From: https://www.cnblogs.com/yang-2018/p/17275560.html