当前位置:网站首页>First acquaintance with Flask
First acquaintance with Flask
2022-07-31 05:43:00 【The flowers are blooming in the south of the city^】
Flask Framework Components
Flask_sqlalchemy: A good combination of Flask and SQLAlchemy, such as ORM operations in django
flask_script: used to generate commands, use commands in the project root directory path; for example: python manage.py runserver
flask_migrate: used to implement database migration (depending on flask_script)
flask-session: session is placed in redis
blinker: signal - trigger signal. Mainly to allow developers to customize some behaviors during the flask request process
Briefly describe the Flask context management process
There are two contexts in Flask, **request context** and **application context**.
1. Request context: saves the data that the client and server interact with.
Application context: some configuration information saved during the running process of the flask program, such as program file name, database connection, user information, etc.
request and session belong to the request context object.
request: Encapsulates the content of the HTTP request, which is for the HTTP request.Example: user = request.args.get('user'), which gets the parameters of the get request.
Session: used to record the information in the request session, for user information.For example: session['name'] = user.id, user information can be recorded.You can also get user information through session.get('name')
current_app and g both belong to the application context object.
current_app: Indicates the program instance of the currently running program file.
g: The object used for temporary storage when processing requests, this variable will be reset for each request.For example: we can obtain some user information for temporary requests.
When calling app = Flask(_name_), the program application object app is created;
request When every http request occurs, the WSGI server calls Flask.call(); then the request object created inside Flask;
The life cycle of the app is longer than request and g. During the life of an app, multiple http requests may occur, so there will be multiple requests and g.
Finally, the view function is passed in, and the response object is generated by return, redirect or render_template and returned to the client.
边栏推荐
猜你喜欢

If the account number or password is entered incorrectly for many times, the account will be banned.

剑指offer基础版 --- 第24天

gin框架学习-Casbin进阶之策略管理API使用方法

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

Swordsman Offer Special Assault Edition --- Day 3

12 【网页布局总结 元素的显示与隐藏】

Lock wait timeout exceeded解决方案

继承、Super,重写、抽象类、抽象方法 1(第七天)

剑指offer专项突击版 ---- 第 6 天

vulhub靶场学习日记xxe-lab
随机推荐
代码执行漏洞
剑指offer基础版 ---- 第26天
基于web3.0使用钱包Metamask的三方登陆
Three-party login using wallet Metamask based on web3.0
联盟链的真实场景在哪里
gin框架学习-JWT认证
解决响应式数据依赖响应式数据无响应问题
C语言的文件操作(一)
三次握手与四次挥手
剑指offer专项突击版 ---- 第 6 天
leetcode-每日一题735. 行星碰撞(栈模拟)
[MQ I can speak for an hour]
数据库上机实验7 数据库设计
vulhub靶场学习日记SickOs1.2
C语言实验四 循环结构程序设计(一)
wpf ScrowViewer水平滚动
Kubernetes 证书可用年限修改
Proteus 8 Professional安装教程
字符串的新增方法
踏上编程之路,你必须要干的几件事