示例代码
home文件下__init__.py文件
from flask import Blueprint
# 1.创建蓝图对象
home_blue = Blueprint('home_b', __name__, url_prefix='/home')
from . import views
home文件下views.py文件
from flask import url_for
from . import home_blue
# 3.使用蓝图对象来注册路由
@home_blue.route('/index')
def index():
url1 = url_for('home_b.index')
print(url1)
return 'index'
main.py文件
from flask import Flask
from home import home_blue
app = Flask(__name__)
# 3.注册蓝图
app.register_blueprint(home_blue)
if __name__ == '__main__':
app.run(debug=True)
920

被折叠的 条评论
为什么被折叠?



