当前位置:网站首页>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
边栏推荐
- _ FindText error
- 高德地图搜索、拖拽 查询地址
- Go对文件操作
- C byte array (byte []) and string are converted to each other
- How to read literature
- ES6 face test questions (reference documents)
- ES6 new method
- C network related operations
- Classification of cifar100 data set based on convolutional neural network
- Anchor location - how to set the distance between the anchor and the top of the page. The anchor is located and offset from the top
猜你喜欢
Nat commun | current progress and open challenges of applied deep learning in Bioscience
.104History
Go file operation
Operation of 2022 mobile crane driver national question bank simulation examination platform
Welcome to the markdown editor
Land cover / use data product download
Operators in C language
[UDS unified diagnostic service] IV. typical diagnostic service (4) - online programming function unit (0x34-0x38)
[UDS unified diagnostic service] v. diagnostic application example: Flash bootloader
2022年茶艺师(初级)考试模拟100题及模拟考试
随机推荐
2022年茶艺师(初级)考试模拟100题及模拟考试
Go's gin framework learning
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (2)
土地覆盖/利用数据产品下载
Realsense selection comparison d455 d435i d415 t265 3D hardware comparison
Implementation of k8s redis one master multi slave dynamic capacity expansion
[binary number] maximum depth of binary tree + maximum depth of n-ary tree
Leak detection and vacancy filling (VIII)
Implementation of object detection case based on SSD
C1小笔记【任务训练篇二】
2022 Jiangxi energy storage technology exhibition, China Battery exhibition, power battery exhibition and fuel cell Exhibition
2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
Flask项目的部署详解
Romance in C language
Clion installation tutorial
Operation of 2022 mobile crane driver national question bank simulation examination platform
Logic regression principle and code implementation
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
Compilation principle first set follow set select set prediction analysis table to judge whether the symbol string conforms to the grammar definition (with source code!!!)
JS implementation private attribute