【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" >
相关推荐
夏天拐跑了西瓜7 小时前
一文入门LangChain:从框架认知到构建你的第一个AI Agent
python·langchain·conda·agent
奕鼎竜瑆7 小时前
Solid 前端响应式开发从零到精通
前端·人工智能
动恰客流统计7 小时前
景区客流统计怎么做?兼顾管控与运营的实施方案解析
大数据·前端·人工智能
魔猴疯猿7 小时前
从0到1用Python开发第一个智能体
人工智能·python·深度学习·神经网络·机器学习
派小心.8 小时前
A/B测试工具免费版够用吗?
前端·数据分析
xiaoqi01958 小时前
机器学习因子分析实战:从量化特征到可视化决策
人工智能·python·机器学习
前端snow9 小时前
ai agent --- redis 缓存
前端
Escalating_xu9 小时前
【Python】基础语法(1):常量、变量、类型、输入输出与运算符
开发语言·python
happylifetree9 小时前
Python14:核心语法-数据存储与运算-字符串定义
python
hhb_6189 小时前
AIRAGDebug:一键定位RAG链路异常
人工智能·python·算法