Flask系列04--Flask的蓝图
flask蓝图
一.蓝图
蓝图(Blueprint),类似于实现django中路由分发那种感觉, 可以把Blueprint理解为不能被run的Flask对象
Blueprint实例化时需要的参数

基本使用
from flask import Blueprint
# 把Blueprint理解为 不能被 Run 的 Flask 对象
bp = Blueprint("bp",__name__,url_prefix="/user") # url_prefix是加前缀 "bp"是蓝图的名字,必须要写
@bp.route("/bp",methods=["GET","Post"])
def my_bp():
return "I am bp in user.py"
另一个示例
from flask import Blueprint # 导入 Flask 中的蓝图 Blueprint 模块
from flask import render_template sv = Blueprint(
"sv",
__name__,
template_folder="sv_template",
static_folder="sv_static" # 静态文件目录也是可以独立出来的
)
# 实例化一个蓝图(Blueprint)对象
# 每个蓝图都可以为自己独立出一套template模板文件夹,如果不写则共享项目目录中的templates @sv.route("/svlist")
def view_list():
return render_template("svlist.html")
二.蓝图结构
通过一个对学生信息在内存中进行增删改查的示例来说明蓝图结构

使用蓝图的基本结构, 其实和django中的差不多,其中
__init__.py
from flask import Flask
from .views import users,select,update,delete,add def create_app():
app = Flask(__name__) app.register_blueprint(users.users)
app.register_blueprint(select.select)
app.register_blueprint(update.update)
app.register_blueprint(delete.delete)
app.register_blueprint(add.add)
return app
manage.py
from app01 import create_app
from app01 import settings app = create_app()
app.config.from_object(settings.DebugSetting)
# app.config.from_object(settings.TestSetting) if __name__ == '__main__': app.run()
三.操作注意

在这里将模版文件夹标记,就可在pycharm中自动提示html文件了

模版语言要选择Jinja2, 否则按tab无法自动补全模版语言
Flask系列04--Flask的蓝图的更多相关文章
- Flask系列(二)Flask基础
知识点回顾 1.flask依赖wsgi,实现wsgi的模块:wsgiref(django),werkzeug(flask),uwsgi(上线) 2.实例化Flask对象,里面是有参数的 app = F ...
- Flask系列(六)Flask实例化补充及信号
一.实例化补充 instance_path和instance_relative_config是配合来用的. 这两个参数是用来找配置文件的,当用app.config.from_pyfile('setti ...
- Flask系列(三)蓝图、基于DButils实现数据库连接池、上下文管理
知识点回顾 1.子类继承父类的三种方式 class Dog(Animal): #子类 派生类 def __init__(self,name,breed, life_value,aggr): # Ani ...
- Flask系列06--(中间件)Flask的特殊装饰器 before_request,after_request, errorhandler
一.使用 Flask中的特殊装饰器(中间件)方法常用的有三个 @app.before_request # 在请求进入视图函数之前 @app.after_request # 在请求结束视图函数之后 响应 ...
- Flask系列(四)Flask实现简单页面登陆
from flask import Flask,render_template,request,redirect,session app = Flask(__name__,template_folde ...
- Flask系列(五)Flask实现分页
一.flask分页组件 from urllib.parse import urlencode,quote,unquote class Pagination(object): ""& ...
- Flask 系列之 部署发布
说明 操作系统:Windows 10 Python 版本:3.7x 虚拟环境管理器:virtualenv 代码编辑器:VS Code 实验目标 通过 Windows 的 WSL,将我们的项目网站部署到 ...
- flask --- 02. 路由, 初始化配置,蓝图
一.Flask 路由 1.添加路由的方式 ① ② 实例: ① @app.route("/my_de") def detail() ② def detail() app.add_ur ...
- Flask最强攻略 - 跟DragonFire学Flask - 第九篇 Flask 中的蓝图(BluePrint)
蓝图,听起来就是一个很宏伟的东西 在Flask中的蓝图 blueprint 也是非常宏伟的 它的作用就是将 功能 与 主服务 分开怎么理解呢? 比如说,你有一个客户管理系统,最开始的时候,只有一个查看 ...
- 【Python】Flask系列-URL和视图笔记
1.学习目标 熟悉Flask相关知识. 熟悉web开发流程. 能独立开发Flask项目. 2.环境配置 Python虚拟环境安装 因为python的框架更新迭代太快了,有时候需要在电脑上存在一个框架的 ...
随机推荐
- js网页上画图
保存 1.d3.js (http://www.d3.org/)使用svg技术,展示大数据量,动态效果很好,但是API暴露的不好,得靠自己摸索. 2.http://raphaeljs.com/refe ...
- JS高级-Date- Error-***Function:
1. Date: API: 1. 8个单位: FullYear Month Date Day Hours Minutes Seconds Milliseconds 2. 每 ...
- boost--BOOST_AUTO、typeof、result_of
1.BOOST_AUTO BOOST_AUTO的功能类似于auto和any,可以用来定义任意类型数据,且可以在编译时自动推导出表达式的类型.BOOST_AUTO属于boost中的typeof库,使用需 ...
- python基本数据类型之字符串(一)
python中字符串中有很多方法,具体方法如下图所示: 分割方法 字符串的分割方法: 1.join方法: join方法是字符串方法中最重要的方法之一,它的作用是将某一字符插入到字符串中用作连接. 具体 ...
- DocumentType类型
并不常用 nodeType 10 nodeName doctype的名称 NodeValue 值为null parentNode Document 不支持子节点 DocumentType不能动态创建, ...
- 怎样导入现有的NiosII工程
查找路径
- AtCoder Beginner Contest-060
A - Shiritori Problem Statement You are given three strings A, B and C. Check whether they form a wo ...
- error C2143: syntax error : missing ';' before 'type'
许久之前,就想看看C和C++,看看这两种神奇的编程语言,但是一直被这样或者那样的琐事给耽搁了(狂喷自己的拖延症). 今天翻开自己的移动硬盘找到一本古老的书籍:<The C Programming ...
- 高性能高可用的分布式唯一ID服务——mooon-uniq-id
目录 目录 1 1. 前言 1 2. 名词 1 3. 功能 1 4. 唯一性原理 2 5. 系统结构 2 5.1. mooon-uniq-agent 2 5.2. mooon-uniq-master ...
- spring 事务的传播特性
1.声明式事物中,一个类serviceA的方法test1()调用另一个类serviceB的方法test2() 要是serviceB的test2()事务配置在xml文件中为REQUIRED,又在此方法上 ...