【flask web】 Blueprint 蓝图 路由模块化

Blueprint 蓝图的作用是:使路由模块化。

1、导入库包:这是是路由文件里面导入的哦

python 复制代码
from flask import Blueprint

例如:

2、导入蓝图配置 :

python 复制代码
from blueprints.auth import auth

3、注册蓝图

python 复制代码
app.register_blueprint(auth)

创建蓝图路由对象的时候:

python 复制代码
bp = Blueprint('auth',__name__,url_prefix="/auth",static_folder="")

bug:静态文件路由

这个是直接从根目录下static文件夹中

python 复制代码
<link rel="stylesheet" href="{{ url_for('static',filename='css/init.css') }}">

然后利用蓝图路由对象可以设置静态文件的文件夹地址。

python 复制代码
bp = Blueprint('auth',__name__,url_prefix="/auth",static_folder="")
python 复制代码
<link rel="stylesheet" href="{{ url_for('auth.static', filename='style.css') }}" rel="external nofollow" rel="external nofollow" >
相关推荐
倔强青铜三1 分钟前
苦练Python第41天:如何用dir() 函数“透视一切”
人工智能·python·面试
倔强青铜三6 分钟前
苦练Python第40天:模块加载与项目组织,让代码像乐高一样可复用!
人工智能·python·面试
lichenyang45329 分钟前
Vue状态管理工具pinia的使用以及Vue组件通讯
前端
腹黑天蝎座30 分钟前
如何更好的封装一个接口轮询?
前端·react.js
AlenLi30 分钟前
JavaScript - 观察者模式的实现与应用场景
前端·设计模式
siroi33 分钟前
【nginx】NJS 的简单实践
前端
饮水机战神35 分钟前
震惊!多核性能反降11%?node接口压力测试出乎意料!
前端·node.js
一只叁木Meow36 分钟前
JavaScript数学库深度对比
前端
顾辰逸you37 分钟前
uniapp--咸虾米壁纸项目(一)
前端·微信小程序
方方洛1 小时前
电子书阅读器:epub电子书文件的解析
前端·产品·电子书