【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" >
相关推荐
用户83562907805115 分钟前
使用 Python 在 Excel 中添加和自定义迷你图
后端·python
用户83562907805126 分钟前
使用 Python 在 Excel 图表中添加趋势线与回归方程
后端·python
用户27050777252436 分钟前
MCP 最小 Server 实测:3 个 JSON-RPC 报错与修法
前端
用户4993350250739 分钟前
一人VIP账号多人共用:Web 代理里的会话共享怎么实现
前端
特立独行的猫A39 分钟前
一份 Markdown 发十个平台:cspub 一稿多投
java·后端·python
用户老李40 分钟前
无线电自学教程 05:第一台收音机——从矿石机到 SDR
前端
IPIPD1 小时前
Node.js请求遇到503怎么重试?先解析Retry-After,再做有上限退避
前端
葡萄城技术团队1 小时前
dsh-spreadjs-editor 的集成链路:把 SpreadJS Designer 嵌进 Agent 工作台
前端
深蓝AI1 小时前
HTTPX 超时 1 秒,接口为何还能跑 2.4 秒?
python
CyrusYiVPP1 小时前
哪个用户会再来买?RFM模型+plotly画出用户分层,数据分析实战第2期
人工智能·python