【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" >
相关推荐
MediaTea13 分钟前
Python:模块 __dict__ 详解
开发语言·前端·数据库·python
jarreyer19 分钟前
python,numpy,pandas和matplotlib版本对应关系
python·numpy·pandas
字节跳动开源41 分钟前
Midscene v1.0 发布 - 视觉驱动,UI 自动化体验跃迁
前端·人工智能·客户端
光影少年1 小时前
三维前端需要会哪些东西
前端·webgl
代码or搬砖1 小时前
HashMap源码
开发语言·python·哈希算法
王林不想说话1 小时前
React自定义Hooks
前端·react.js·typescript
heyCHEEMS2 小时前
Uni-app 性能天坑:为什么 v-if 删不掉 DOM 节点
前端
马致良2 小时前
三年前写的一个代码工具,至今已被 AI Coding 完全取代。
前端·ai编程
橙某人2 小时前
LogicFlow 交互新体验:让锚点"活"起来,鼠标跟随动效实战!🧲
前端·javascript·vue.js
借个火er2 小时前
依赖注入系统
前端