当前位置:网站首页>Flask 的初识
Flask 的初识
2022-07-31 05:09:00 【城南花开了^】
Flask框架组件
Flask_sqlalchemy:将Flask和SQLAlchemy很好的结合在一起,如django中的ORM操作
flask_script:用于生成命令,在项目根目录路径下使用命令;例如:python manage.py runserver
flask_migrate:用来实现数据库迁移(依赖flask_script)
flask-session:session放在redis里面
blinker:信号-触发信号.主要是让开发者可是在flask请求过程中定制一些行为
简述Flask上下文管理流程
Flask中有两种上下文,**请求上下文**和**应用上下文**.
1. 请求上下文:保存了客户端和服务器交互的数据。
应用上下文:在flask程序运行过程中,保存的一些配置信息,比如程序文件名、数据库的连接、用户信息等
request和session都属于请求上下文对象。
request:封装了HTTP请求的内容,针对的是http请求。举例:user = request.args.get('user'),获取的是get请求的参数。
session:用来记录请求会话中的信息,针对的是用户信息。举例:session['name'] = user.id,可以记录用户信息。还可以通过session.get('name')获取用户信息
current_app和g都属于应用上下文对象。
current_app:表示当前运行程序文件的程序实例。
g:处理请求时,用于临时存储的对象,每次请求都会重设这个变量。比如:我们可以获取一些临时请求的用户信息。
当调用app = Flask(_name_)的时候,创建了程序应用对象app;
request 在每次http请求发生时,WSGI server调用Flask.call();然后在Flask内部创建的request对象;
app的生命周期大于request和g,一个app存活期间,可能发生多次http请求,所以就会有多个request和g。
最终传入视图函数,通过return、redirect或render_template生成response对象,返回给客户端。
边栏推荐
- 1. Get data - requests.get()
- 【LeetCode-SQL每日一练】——2. 第二高的薪水
- 一文了解大厂的DDD领域驱动设计
- DVWA installation tutorial (understand what you don't understand · in detail)
- Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric
- 12个MySQL慢查询的原因分析
- STM32 - DMA
- sql statement - how to query data in another table based on the data in one table
- wx.miniProgram.navigateTo在web-view中跳回小程序并传参
- a different object with the same identifier value was already associated with the session
猜你喜欢

DVWA安装教程(懂你的不懂·详细)
![[MQ I can speak for an hour]](/img/ef/863c994ac3a7de157bd39545218558.jpg)
[MQ I can speak for an hour]
![【JS面试题】面试官:“[1,2,3].map(parseInt)“ 输出结果是什么?答上来就算你通过面试](/img/7a/c70077c7a95137aaeb49c344c82696.png)
【JS面试题】面试官:“[1,2,3].map(parseInt)“ 输出结果是什么?答上来就算你通过面试

Interview Redis High Reliability | Master-Slave Mode, Sentinel Mode, Cluster Cluster Mode

MySQL8.0.26安装配置教程(windows 64位)

CentOS7 - yum install mysql
![[Cloud Native] DevOps (5): Integrating Harbor](/img/5a/dd33d7d3cb0124f328d2d38fff0125.png)
[Cloud Native] DevOps (5): Integrating Harbor

CentOS7 —— yum安装mysql

一文了解大厂的DDD领域驱动设计

mysql存储过程
随机推荐
矩池云快速安装torch-sparse、torch-geometric等包
Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work
ERP Production Operation Control Kingdee
SQL行列转换
The monitoring of Doris study notes
Three oj questions on leetcode
pytorch中的一维、二维、三维卷积操作
Go language study notes - dealing with timeout problems - Context usage | Go language from scratch
Multiple table query of sql statement
Kubernetes 证书可用年限修改
Duplicate entry ‘XXX‘ for key ‘XXX.PRIMARY‘解决方案。
MySQL优化之慢日志查询
CentOS7 install MySQL graphic detailed tutorial
Kubernetes加入集群的TOKEN值过期
Sql解析转换之JSqlParse完整介绍
110 MySQL interview questions and answers (continuously updated)
2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。
a different object with the same identifier value was already associated with the session
tf.keras.utils.pad_sequences()
【LeetCode-SQL每日一练】——2. 第二高的薪水