当前位置:网站首页>03 exception handling, state keeping, request hook -- 04 large project structure and blueprint
03 exception handling, state keeping, request hook -- 04 large project structure and blueprint
2022-07-26 08:48:00 【Candy is not sweet】
1.session and cookie The difference between
cookie The shortcomings of : Data can be modified in series , Customers can make changes at will
solve :cookie adopt session Modify the client , And it's encrypted
2.Cookie The implementation of the
2.1.cookie An increase in
from flask import Flask,response
app=Flask(__name__) # Instantiate data
# Define a function
@app.route('/set_cookie')
def set_cookie():
# The response object make_response The value returned
resp=make_response(' Set up cookie')
# Set up cookie max_age cookie The validity of the
resp.set_cookie('name','zhangsan',max_age=60)
# Response return
return resp
if __name__=='__main__':
app.run()
result :
Display the time of validity, etc : What I set up is 60s
2.2.cookie Investigation of
from flask import Flask
app=Flask(__name__)
# Define a route
@app.route('/get_cookie')
def get_cookie():
name=request.cookies.get('name')
resp=make_response(' obtain cookie')
return resp
# perform
if __name__='__main__':
app.run()
2.3cookie The deletion of
# Import flask package
from flask import Flask
# Instantiate
app=Flask(__name__)
# Define routes
@app.route('/del_cookie')
# Define a cookie Function of
def del_cookie():
resp=make_response(' Delete cookie')
resp.del_cookie('name')
return resp
if __name__='__main__':
app.run()
1. Introduction and use of blueprints
The concept of blueprint :
Blueprint is an extension of existing Flask The method of applying structure , It also provides a way to combine views with similar functions , In short, it is equivalent to the air conditioner The remote control
Steps of blueprint ( The three step ):
One : Create a blueprint object
Two : Operate on the created blueprint object
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')
3、 ... and : Register the blueprint object on the application object
边栏推荐
- [freeswitch development practice] user defined module creation and use
- Registration of finite element learning knowledge points
- Automation and disconnection monitoring of video addition
- Implementation of Prometheus web authentication and alarm
- Flutter upgrade 2.10
- In the first year of L2, the upgrade of arbitrum nitro brought a more compatible and efficient development experience
- Oracle 19C OCP 1z0-082 certification examination question bank (36-41)
- [recommended collection] MySQL 30000 word essence summary index (II) [easy to understand]
- Excel delete blank lines
- 基于Raft共识协议的KV数据库
猜你喜欢
随机推荐
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
Super potential public chain dfinity -- the best time for DFI developers to enter
Excel delete blank lines
[suggestions collection] summary of MySQL 30000 word essence - locking mechanism and performance tuning (IV) [suggestions collection]
【加密周报】加密市场有所回温?寒冬仍未解冻 盘点上周加密市场发生的重大事件
Oracle 19C OCP 1z0-083 question bank (7-12)
Human computer interaction software based on C language
The data read by Flink Oracle CDC is always null. Do you know
[recommended collection] MySQL 30000 word essence summary + 100 interview questions (I)
【FreeSwitch开发实践】使用SIP客户端Yate连接FreeSwitch进行VoIP通话
Hegong sky team vision training Day6 - traditional vision, image processing
Xshell batch send command to multiple sessions
Arbitrum Nova release! Create a low-cost and high-speed dedicated chain in the game social field
Mysql8 one master one slave +mycat2 read write separation
Espressif 玩转 编译环境
pl/sql之集合
What are the differences in the performance of different usages such as count (*), count (primary key ID), count (field) and count (1)? That's more efficient
keepalived双机热备
PXE principles and concepts
Which financial product has the highest yield in 2022?