当前位置:网站首页>03异常处理,状态保持,请求钩子---04大型项目结构与蓝图
03异常处理,状态保持,请求钩子---04大型项目结构与蓝图
2022-07-26 08:38:00 【糖果ᨐ不甜丫꧂】
1.session和cookie的区别
cookie的缺点:可以串改数据,客户可以随意串改
解决:cookie通过session客户端进行修改,并且是加密的
2.Cookie的实现
2.1.cookie的增加
from flask import Flask,response
app=Flask(__name__) # 实例化数据
# 定义一个函数
@app.route('/set_cookie')
def set_cookie():
# 响应对象 make_response 返回的值
resp=make_response('设置cookie')
# 设置cookie max_age cookie的有效期
resp.set_cookie('name','zhangsan',max_age=60)
# 响应返回
return resp
if __name__=='__main__':
app.run()
结果:
显示有效期的时间等:我设置的是60s
2.2.cookie的查
from flask import Flask
app=Flask(__name__)
# 定义一个路由
@app.route('/get_cookie')
def get_cookie():
name=request.cookies.get('name')
resp=make_response('获取cookie')
return resp
# 执行
if __name__='__main__':
app.run()
2.3cookie的删除
# 导入flask包
from flask import Flask
# 实例化一下
app=Flask(__name__)
# 定义路由
@app.route('/del_cookie')
# 定义一个cookie的函数
def del_cookie():
resp=make_response('删除cookie')
resp.del_cookie('name')
return resp
if __name__='__main__':
app.run()
1.蓝图的介绍和使用
蓝图的概念:
蓝图是一种扩展已有Flask应用结构的方法,并且提供易总功能类似的视图组合在一起的方式,简单来说就相当于与空调的遥控器
蓝图的步骤(三步):
一:创建一个蓝图对象
二:在创建好的蓝图对象进行操作
from flask import Flask,Blueprint,jsonify
from flask_restful import Api,Resource,reqparse
from models.model import *
user_db=Blueprint('user_db',__name__,url_prefix='/user')
api=Api(user_db)
class HomeView(Resource):
def get(self):
...
def post(self):
...
def put(self):
...
def delete(self):
...
api.add_resource(HomeView,'/home')
三:在应用对象上注册蓝图对象
边栏推荐
- 为什么要在时钟输出上预留电容的工位?
- 2022-7-9 personal qualifying 6 competition experience
- 22-07-12 personal training match 1 competition experience
- Excel find duplicate lines
- 2022-7-4 personal qualifying 1 competition experience
- Write common API tools swagger and redoc
- Foundry教程:使用多种方式编写可升级的智能合约(上)
- Please tell me if there is any way to increase the write out rate when the Flink SQL client is in the sink table. When synchronizing through sink table
- Install HR schema, example, and Scott schema on Oracle and MySQL
- Code cloud change remote warehouse command
猜你喜欢

Excel delete blank lines

shell编程

Super nice navigation page (static page)

Mycat2 sub database and sub table
![[freeswitch development practice] use SIP client Yate to connect freeswitch for VoIP calls](/img/8b/d5792a00fc5798d3d960f1f1b1088e.png)
[freeswitch development practice] use SIP client Yate to connect freeswitch for VoIP calls

Code cloud change remote warehouse command
![[abstract base class inheritance, DOM, event - learning summary]](/img/0e/4c4ed97814d49d72a5994ce2a53c88.png)
[abstract base class inheritance, DOM, event - learning summary]
![[GUI] GUI programming; AWT package (interface properties, layout management, event monitoring)](/img/25/475c91d7e673fda3930e5a69be0f28.png)
[GUI] GUI programming; AWT package (interface properties, layout management, event monitoring)

2022-7-9 personal qualifying 6 competition experience

Using the primitive root of module m to judge and solve
随机推荐
CV learning notes (optical flow)
Flutter text is left aligned with no blank space in the middle
Error handling response: Error: Syntax error, unrecognized expression: .c-container /deep/ .c-contai
[abstract base class inheritance, DOM, event - learning summary]
Mysql8 dual master and dual slave +mycat2 read / write separation
Nodejs2day (modularization of nodejs, NPM download package, module loading mechanism)
What are the contents of Oracle OCP and MySQL OCP certification exams?
Add in the registry right click to open in vscode
The full name of flitter IDFA is identity for advertisers, that is, advertising identifiers. It is used to mark users. At present, it is most widely used for advertising, personalized recommendation,
Using the primitive root of module m to judge and solve
Pxe原理和概念
Redis进阶
Oracle 19C OCP 1z0-082 certification examination question bank (13-18)
Does flinkcdc now support sqlserver instance name connection?
P1825 [USACO11OPEN]Corn Maze S
2022-7-5 personal qualifying 2 competition experience
23.8 using the applicationrunner or commandlinerunner to implement applicationrunner and commandlinerunner
Oracle 19C OCP 1z0-082 certification examination question bank (7-12)
Sub Chocolate & paint area
Kotlin program control