【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" >
相关推荐
九酒7 分钟前
性能优化:500w字符编码需要多少时间?
前端·性能优化
AntBlack9 分钟前
别说了别说了 ,Trae 已经在不停优化迭代了
前端·人工智能·后端
天天扭码38 分钟前
2025年了,npm 与 pnpm我们该如何选择
前端·javascript·npm
烛阴40 分钟前
10个JavaScript编程技巧,助你成为高效开发高手!
前端·javascript
去伪存真40 分钟前
ESLint + Husky 如何只扫描发生改动的文件?
前端·eslint
s9123601011 小时前
rust REGEX和lazy_static 和struct 混用
java·前端·javascript
pyengine1 小时前
基于pandoc的MarkDown格式与word相互转换小工具开发(pyqt5)
开发语言·python·qt·word
YuSun_WK1 小时前
配置MambaIRv2: Attentive State Space Restoration的环境
开发语言·python
Nick_zcy1 小时前
开发基于python的商品推荐系统,前端框架和后端框架的选择比较
开发语言·python·前端框架·flask·fastapi
vvilkim1 小时前
React 与 Vue 虚拟 DOM 实现原理深度对比:从理论到实践
前端·vue.js·react.js