python - flask0.1源码当中的SharedDataMiddleware是什么意思?
大家讲道理
大家讲道理 2017-04-18 10:01:40
0
2
729

源码如下

class Flask(object):
    def __init__(self, package_name):
        if self.static_path is not None:
            self.url_map.add(Rule(self.static_path +'/<filename>',
                                  build_only=True, endpoint='static'))
            if pkg_resources is not None:
                target = (self.package_name, 'static')
            else:
                target = os.path.join(self.root_path, 'static')
            self.wsgi_app = SharedDataMiddleware(self.wsgi_app, {
                self.static_path: target
            })

看了werkzeug这部分的文档,还是没有理解意思,可以解释一下吗?谢谢:-)

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
阿神

Middleware is a concept in wsgi, used to package your app. After packaging, you can do other processing before and after the packaged part is called:

[Middleware处理一下输入] -> [APP] -> [Middleware处理一下APP的输出]

Specifically, SharedDataMiddleware actually handles static content (such as js, pictures...). Before the APP is called, check whether the static file can be returned directly. If it can, return it directly. Don't call the APP. If it can't, just return it directly. Continue to call the APP.

阿神

The bottom layer of flask uses werkzeug. It is recommended that you take a look at the werkzeug middlewares document

oraoto’s explanation is also spot on.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template