当前位置:网站首页>Cookie addition, deletion, modification and exception
Cookie addition, deletion, modification and exception
2022-07-27 08:33:00 【pink_ Pig___】
cookie Addition, deletion and modification of
from flask import Flask, make_response, request
app = Flask(__name__)
# add to cookie
@app.route('/set_cookie')
def set_cookie():
resp = make_response(' Set up cookie')
resp.set_cookie('name', 'zhangsan', max_age=60) # Set up cookie
return resp
# modify cookie, That's reset value
@app.route('/put_cookie')
def set_cookie():
resp = make_response(' modify cookie')
resp.set_cookie('name', 'wangwu', max_age=60) # Set up cookie
return resp
# obtain cookie
@app.route('/get_cookie')
def get_cookie():
name = request.cookies.get('name')
print(name)
resp = make_response(' obtain cookie')
return resp
# Delete cookie
@app.route('/del_cookie')
def del_cookie():
resp = make_response(' Delete cookie')
resp.delete_cookie('name')
return resp
if __name__ == '__main__':
app.run()
session Has been deleted, modified and checked
- Need to make a bag , Write the key
# Value can be written freely
SECRET_KEY = 'ajfijfakjfg'
from flask import Flask, make_response, session
app = Flask(__name__)
# Call key
app.config.from_pyfile(settings.py)
# add to session
@app.route('/set_session')
def set_session():
session['password'] = 123456
return 'session Set up the success '
# modify session, It's also a reset value
@app.route('/set_session')
def set_session():
session['password'] = 11111
return 'session Modification successful '
# obtain session
@app.route('/get_session')
def get_session():
pwd = session.get('password')
return f' Acquired key:{
pwd}'
# Delete session
@app.route('/del_session')
def del_session():
resp = make_response(' Delete session')
resp.delete_cookie('session')
return resp
if __name__ == '__main__':
print(app.config)
app.run()
Throw an exception
from flask import Flask, abort
app = Flask(__name__)
@app.route('/error')
def error():
abort(404)
# Capture exception
@app.errorhandler(404)
def get_error(e):
return ' Something went wrong '
if __name__ == '__main__':
app.run()
Construction method
@app.route('/page')
def page():
print(' Page execution ')
return ' Page execution '
@app.before_first_request
def first():
print(' Execute before page request , Request only once ')
@app.before_request
def before():
print(' Every time you execute ')
@app.after_request
def after(resp):
print(resp)
resp.status = 404
print(' The page processing request result reports an error , May not be implemented ')
return resp
@app.teardown_request
def tr(e):
print(' The page executes after processing the request , Error reporting will also be implemented ')
if __name__ == '__main__':
app.run()
边栏推荐
- All in one 1353 -- expression bracket matching (stack)
- Installation and use of Supervisor
- 虚拟机克隆
- Flask one to many database creation, basic addition, deletion, modification and query
- Help send some recruitment. If you are interested, you can have a look
- 情人节,我用字符画出了一个对象!
- Use of "PHP Basics" Boolean
- Block, there is a gap between the block elements in the row
- Flutter 渲染机制——GPU线程渲染
- 信息化项目风险控制与应用
猜你喜欢

pytorch_ demo1

How to merge multiple columns in an excel table into one column

Vertical align cannot align the picture and text vertically

Background image related applications - full, adaptive

带宽 与 货币

Functions and arrow functions

Fluent rendering mechanism - GPU thread rendering

Vcenter7.0 managing esxi7.0 hosts

Attack and defense world MFW

Use of "PHP Basics" delimiters
随机推荐
openGauss之TryMe初体验
1176 questions of Olympiad in informatics -- who ranked K in the exam
Minio 安装与使用
Solution to the program design of the sequence structure of one book (Chapter 1)
Background order management
You may need an additional loader to handle the result of these loaders.
MCDF top level verification scheme
第2章 前台数据展现
SSTI template injection
Vertical align cannot align the picture and text vertically
Zhongang Mining: the new energy industry is developing rapidly, and fluorine chemical products have a strong momentum
Node installation and debugging
Plato farm is expected to further expand its ecosystem through elephant swap
Flask one to many database creation, basic addition, deletion, modification and query
Connection failed during installation of ros2 [ip: 91.189.91.39 80]
[MRCTF2020]Ezpop 1
帮忙发几个招聘,有兴趣可以看看
说透缓存一致性与内存屏障
Interviewer: what is scaffolding? Why do you need scaffolding? What are the commonly used scaffolds?
Development of three database general SQL code based on PG Oracle and MySQL