【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" >
相关推荐
Penge6661 小时前
JavaScript:BOM 详解
前端
Penge6661 小时前
Vite vs Webpack:前端构建工具原理与实战
前端
Penge6661 小时前
前端包管理工具:npm、Yarn、pnpm 快速入门
前端
Penge6662 小时前
Sass 了解
前端
Penge6662 小时前
Webpack 打包从 0 到 1 实战笔记
前端
大可不必了2 小时前
03 函数定义和调用
开发语言·python
Penge6662 小时前
Webpack 入门:是什么、为什么需要、怎么使用?
前端
Penge6663 小时前
Ant Design(Antd)了解
前端
wangruofeng3 小时前
同一行代码,百种渲染:Asuka、React Native 与 Flutter 跨平台渲染机制深度拆解
前端·github
承渊政道3 小时前
【Python编程—从入门到实践】(记分与闯关:用Python+Pygame,打造越战越精彩的太空大战!)
开发语言·python·pycharm·游戏程序·pygame