【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" >
相关推荐
智购科技无人售货机工厂店2 分钟前
2026自动售货机大屏交互设计原则:从信息层级到视觉动线的工程实践~YH
运维·python·单片机·嵌入式硬件·自动化·交互
quantdash_cc7 分钟前
量化数据源怎么选:稳定性、实时性和数据完整性到底该如何权衡?
开发语言·python·数据分析·量化交易·股票数据·quantdash
郭邯15 分钟前
从零到一:我用 AI 写了个复利计算器,顺便治好了我的"公式恐惧症"
前端
Pointer Pursuit18 分钟前
C++11特性(二)
前端·c++·算法
天道kabuto23 分钟前
Vue3 升级踩坑:子组件 click 事件为什么会触发两次?
前端
Nayana24 分钟前
《Web 到 HarmonyOS》-- Ability、Stage、模块化与路由导航
前端
hfywmsj29 分钟前
广州餐饮铺位招租数据分析:选址权重模型与租金评估实操
人工智能·python·数据分析·广州餐饮铺位招租
cui_ruicheng38 分钟前
FastAPI 应用开发(一):FastAPI、路由参数与交互式 API 文档
python·fastapi
小柯南敲键盘1 小时前
跨境电商翻译工具,AI批量图片及视频字幕翻译
大数据·人工智能·python·音视频
ShineWinsu1 小时前
对于 Vue 3:从为什么学 Vue,到声明式渲染与数据响应式的解析
前端·javascript·vue.js