当前位置:网站首页>Flash - Middleware
Flash - Middleware
2022-04-23 17:58:00 【Feng Ye 520】
It's actually encapsulating old wine , Put in a new bottle , Add some more stuff yourself . Retention pit , It's not used yet .
Flask Your request extension is Django Middleware .Django The middleware is not Flask Middleware
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello World!'
class Md(object):
def __init__(self,old_wsgi_app):
self.old_wsgi_app = old_wsgi_app
def __call__(self, environ, start_response):
print(' Before the start ')
# ... Some custom actions
ret = self.old_wsgi_app(environ, start_response)
# ... Some custom actions
print(' After that ')
return ret
if __name__ == '__main__':
# Encapsulate the old app.wsgi_app, This is a app.run() Principle , Look at the source code . Would call __call__ Method
app.wsgi_app = Md(app.wsgi_app)
app.run()
from flask import Flask, flash, redirect, render_template, request
app = Flask(__name__)
app.secret_key = 'some_secret'
@app.route('/')
def index1():
return render_template('index.html')
@app.route('/set')
def index2():
v = request.args.get('p')
flash(v)
return 'ok'
class MiddleWare:
def __init__(self,wsgi_app):
self.wsgi_app = wsgi_app
def __call__(self, *args, **kwargs):
return self.wsgi_app(*args, **kwargs)
if __name__ == "__main__":
app.wsgi_app = MiddleWare(app.wsgi_app)
app.run(port=9999)
problem : Is this Flask-extensions Implementation principle of ? See that it is extended by a third party . Future research
版权声明
本文为[Feng Ye 520]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230546134146.html
边栏推荐
- EasymodbusTCP之clientexample解析
- Some questions some questions some questions some questions
- Generate verification code
- Commonly used functions -- spineros:: and spineros::)
- 开源按键组件Multi_Button的使用,含测试工程
- 587. 安装栅栏 / 剑指 Offer II 014. 字符串中的变位词
- .104History
- C1 notes [task training chapter I]
- String function in MySQL
- [appium] write scripts by designing Keyword Driven files
猜你喜欢
The ultimate experience, the audio and video technology behind the tiktok
Operation of 2022 mobile crane driver national question bank simulation examination platform
QTableWidget使用讲解
Dry goods | how to extract thumbnails quickly?
Error in created hook: "referenceerror:" promise "undefined“
On the problem of V-IF display and hiding
.104History
极致体验,揭晓抖音背后的音视频技术
2022年茶艺师(初级)考试模拟100题及模拟考试
An example of linear regression based on tensorflow
随机推荐
Build openstack platform
Classification of cifar100 data set based on convolutional neural network
Qtablewidget usage explanation
C1 notes [task training chapter I]
Open source key component multi_ Button use, including test engineering
C#字节数组(byte[])和字符串相互转换
Halo 开源项目学习(二):实体类与数据表
Flask项目的部署详解
Where is the configuration file of tidb server?
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)
Implementation of k8s redis one master multi slave dynamic capacity expansion
.104History
Examination question bank and online simulation examination of the third batch (main person in charge) of special operation certificate of safety officer a certificate in Guangdong Province in 2022
Process management command
vite配置proxy代理解决跨域
Notes on common basic usage of eigen Library
_ FindText error
Nanotechnology + AI enabled proteomics | Luomi life technology completed nearly ten million US dollars of financing
Go file operation
Future usage details