Flask-蓝图

当两个路由前缀一致时,可以使用蓝图。

参考:Flask(9)- 蓝图的基本使用 - 小菠萝测试笔记 - 博客园

"""
实例化蓝图对象
第一个参数:蓝图名称
第二个参数:导入蓝图的名称
第三个参数:蓝图前缀,该蓝图下的路由规则前缀都需要加上这个
"""
blueprint = Blueprint('news', __name__, url_prefix="/news", template_folder="templates", static_folder="static")


# 用蓝图注册路由
@blueprint.route("/society/")
def society_news():
    return render_template('society.html')
# 注册蓝图
app.register_blueprint(news.blueprint)

参考文章还讲解了一下比较好的,可扩展的程序结构:每个蓝图一个文件夹,用来管理蓝图下的资源。

猜你喜欢

转载自blog.csdn.net/seanyang_/article/details/125772408