【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" >
相关推荐
Coodor几秒前
使用web也可以写NFC微信小程序拉取
前端·微信小程序·小程序·nfc拉起小程序
SamChan903 分钟前
Python+PyMuPDF提取PDF表格并翻译:表格结构检测与双语重建实战
windows·python·ai·pdf·wpf
weixin_307779134 分钟前
PySpark根据输入的表名和过滤条件生成 INSERT 语句
python·spark·云计算·big data
GodSure091410 分钟前
Java单一职责原则SRP详解
java·python·单一职责原则
Mojitocean20 分钟前
Win开发环境配置(持续更新)
开发语言·python
千里码aicood28 分钟前
flask基于数字人的储粮知识问答原型系统研究与实现
后端·python·flask
E_ICEBLUE35 分钟前
Python 实现 Markdown 转 Word、PDF:从转换到页面设置
python·pdf·word·markdown·格式转换
哒咩哒咩12938 分钟前
Agent 智能体开发全攻略:从 ReAct 到企业级架构
python·langchain·fastapi
H愚公移山H1 小时前
Tengine2.4.1 + OpenSSL1.1.1w 全平台编译踩坑手册(CentOS7 x86_64|Linux x64|ARM64|2026实战复盘)
python