【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" >
相关推荐
happylifetree4 小时前
Python09:核心语法-数据存储与运算-字面量
python
前端snow4 小时前
ai agent --- postgreSQL 关系型数据库
前端
心之语歌5 小时前
Tkinter 画布基本梳理
运维·服务器·python
Wx-bishekaifayuan5 小时前
django个性化旅游路线推荐平台49005-计算机课程设计、毕业设计
spring boot·后端·python·django·课程设计·express·旅游
卷无止境5 小时前
ECharts:把数据变成故事的可视化利器
前端
Eric_见嘉5 小时前
在职前端 Skill 和 MCP 分享
前端·后端·agent
liangshanbo12156 小时前
面试题:如何优化 Webpack 的打包速度?
前端·webpack·node.js
wengad6 小时前
从 wangEditor 迁到 wangEditor-next
前端·javascript·vue.js
小白快快跑哦6 小时前
python-字符串全解(六):正则表达式-量词
python·正则表达式·字符串
禹凕6 小时前
机器学习之Selenium(Machina Learning about Selenium)
爬虫·python·selenium·测试工具·机器学习