当前位置:网站首页>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 
边栏推荐
- 【数据库 】GBase 8a MPP Cluster V95 安装和卸载
- 23.2 customizing the banner control display hidden banner modify banner
- Okaleido上线聚变Mining模式,OKA通证当下产出的唯一方式
- Winter vacation homework & Stamp cutting
- 【搜索专题】看完必会的搜索问题之洪水覆盖
- Vision Group Training Day5 - machine learning, image recognition project
- 六、品达通用权限系统__pd-tools-log
- Why reserve a capacitor station on the clock output?
- One click deployment of lamp and LNMP scripts is worth having
- Mycat2 sub database and sub table
猜你喜欢

基于C#实现的文件管理文件系统

OA项目之我的会议(查询)

基于C语言实现的人机交互软件

KV database based on raft consensus protocol

Mysql8 dual master and dual slave +mycat2 read / write separation

Memory management - dynamic partition allocation simulation

Xshell batch send command to multiple sessions

MySQL 8.0 OCP (1z0-908) has a Chinese exam
![[abstract base class inheritance, DOM, event - learning summary]](/img/0e/4c4ed97814d49d72a5994ce2a53c88.png)
[abstract base class inheritance, DOM, event - learning summary]
![[untitled]](/img/89/c3ab79eb325f0136114a568745924b.png)
[untitled]
随机推荐
六、品达通用权限系统__pd-tools-log
【数据库 】GBase 8a MPP Cluster V95 安装和卸载
[encryption weekly] has the encryption market recovered? The cold winter still hasn't thawed out. Take stock of the major events that occurred in the encryption market last week
Spark scheduling analysis
[database] gbase 8A MPP cluster v95 installation and uninstall
Oracle 19C OCP 1z0-082 certification examination question bank (30-35)
Using the primitive root of module m to judge and solve
Foundry tutorial: writing scalable smart contracts in various ways (Part 1)
Cadence(十)走线技巧与注意事项
Ansible important components (playbook)
23.2 customizing the banner control display hidden banner modify banner
基于C语言设计的换乘指南打印系统
【搜索专题】看完必会的搜索问题之洪水覆盖
CIS 2020 - alternative skills against cloud WAF (pyn3rd)
Flutter WebView three fingers rush or freeze the screen
[abstract base class inheritance, DOM, event - learning summary]
JDBC数据库连接池(Druid技术)
Oracle 19C OCP 1z0-082 certification examination question bank (42-50)
Flutter distribution
Redis advanced