源码如下
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这部分的文档,还是没有理解意思,可以解释一下吗?谢谢:-)
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:
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.