【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" >
相关推荐
2601_958492553 小时前
Optimizing Engagement with Freehead Skate - HTML5 Game - Construct 3
前端·html·html5
Li emily3 小时前
解决了加密货币api多币种订阅时的数据乱序问题
人工智能·python·api·fastapi
2301_781571423 小时前
Golang格式化输出占位符都有什么_Golang fmt占位符教程【通俗】
jvm·数据库·python
asdzx673 小时前
使用 Python 为 PDF 添加页码 (详细教程)
python·pdf·页码
茉莉玫瑰花茶3 小时前
工作流的常见模式 [ 1 ]
java·服务器·前端
AI技术控3 小时前
《Transformers are Inherently Succinct》论文解读:从“能表达什么”到“多紧凑地表达”
人工智能·python·深度学习·机器学习·自然语言处理
zhangxingchao4 小时前
AI应用开发六:企业知识库
前端·人工智能·后端
山峰哥4 小时前
SQL慢查询调优实战:从全表扫描到索引覆盖的完整复盘
前端·数据库·sql·性能优化
红尘散仙5 小时前
一个 `#[uniffi::export]`,把 Rust 接进 React Native
前端·后端·rust