【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" >
相关推荐
赖龙4 小时前
pnpm vs npm
前端·npm·node.js
青 春 记 忆5 小时前
零基础入门Python11|Git实战:为任务管理器建立版本历史
开发语言·git·vscode·python·python3.11
Python私教5 小时前
多个项目怎么安全合并?先适配,再切换
后端·python·架构
学如逆水,不进则退5 小时前
在线免费音频剪辑:NBTools 可视化波形裁剪 MP3/WAV,本地处理免上传
前端·音视频
Mh6 小时前
虚拟滚动真的比普通滚动性能更好吗?
前端·javascript·性能优化
pe7er6 小时前
React + Ant Design 中的 IME (输入法合成)安全输入组件
前端
Super 含6 小时前
Android 启动优化(二):TTID、TTFD 与 Macrobenchmark 启动性能测量
前端
Python私教6 小时前
别急着加 llms.txt:企业官网面向 AI 搜索的工程清单
前端·人工智能·seo
东方小月7 小时前
从零开发一个 Coding Agent(十三):实现安全的 read 文件读取工具
前端·人工智能·全栈
东方小月7 小时前
从零开发一个 Coding Agent(十二):实现版本化 JSONL 与真实 CLI 入口
前端·设计模式·前端框架