【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" >
相关推荐
IT_陈寒39 分钟前
JavaScript的闭包把我坑惨了,说好的内存会自动回收呢?
前端·人工智能·后端
Jackson__1 小时前
分享一个横向滚动案例,带悬停暂停,通用性很强
前端
MariaH2 小时前
git rebase的使用
前端
_柳青杨2 小时前
深入理解 JavaScript 事件循环
前端·javascript
阡陌Jony2 小时前
关于前端性能优化的一些问题:
前端
星云穿梭3 小时前
用Python写一个带图形界面的学生管理系统——完整教程
python
用户600071819103 小时前
【翻译】简化 TSRX
前端
金銀銅鐵3 小时前
用 Pygame 实现 15 puzzle
python·数学·游戏
IT乐手4 小时前
佛德角逼平西班牙,国足还有啥借口?
前端
JustHappy4 小时前
我汇总了身边朋友的经历才发现,其实第一份实习是最难找的......
前端·后端·面试